home *** CD-ROM | disk | FTP | other *** search
/ Delphi 2 - Developers' Solutions / Delphi 2 Developers' Solutions.iso / dds / chap11 / howto05 / cciccfrm.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1996-06-12  |  198.6 KB  |  5,727 lines

  1. unit Cciccfrm;
  2.  
  3. interface
  4.  
  5. uses
  6.   SysUtils, WinTypes, WinProcs, Messages, Classes, Graphics, Controls,
  7.   Forms, Dialogs, ExtCtrls, StdCtrls, Buttons, Menus, FileCtrl, CCWSock, CCICCInf,
  8.   CCICCPrf, IniFiles, Gauges , CCUUCode;
  9.  
  10. type
  11.   { This record holds the information for a number of internet connections }
  12.   PConnectionsRecord = ^TConnectionsRecord;
  13.   TConnectionsRecord = record
  14.     CProfile   : String; { Connection profile; used in lists }
  15.     CIPAddress : String; { Dotted character IP Address       }
  16.     CUserName  : String; { Login name to site; can be anonym }
  17.     CPassword  : String; { Password; won't be shown          }
  18.     CStartDir  : String; { Starting directory; used for FTP  }
  19.   end;
  20.   { Array of TCR }
  21.   CRFile = file of TConnectionsRecord; { File type for TCRec }
  22.   { This record is used to hold information about a newsgroup            }
  23.   { NOTE : hi and low pointers indicate either dl or trashing without dl }
  24.   { "read" is for an article dl'd but not trashed.                       }
  25.   PNewsGroupRecord = ^TNewsGroupRecord;
  26.   TNewsGroupRecord = record
  27.     GName                : String;  { Profile of the newsgroup              }
  28.     GRealName            : String;  { Real Newsrc name of the newsgroup     }
  29.     GLowest              : Longint; { Number of lowest dl/trashed article   }
  30.     GHighest             : Longint; { Number of highest dl/trashed article  }
  31.     GTotalNew            : Longint; { Total New articles available          }
  32.     GTotalAvailable      : Longint; { After update, shows how many arts on s}
  33.     GLowestAvailable     : Longint; { au, shows lowest a# on server         }
  34.     GHighestAvailable    : Longint; { au, shows highest a# on server        }
  35.     GPostable            : Boolean; { Can post to newsgroup                 }
  36.     GSubscribed          : Boolean; { Subscribed to newsgroup               }
  37.     GTotalArticles       : Longint; { Total articles maintained on system   }
  38.     GTotalUnReadArticles : Longint; { Total unread articles on system       }
  39.     GIDNumber            : Integer;
  40.     GFileName            : String;  { Name of file holding articles records }
  41.     GLTag                : Longint; { Tag field to hold pointer to arts TL  }
  42.   end;
  43.   NGRFile = file of TNewsGroupRecord; { File type for NGRec }
  44.   { This record is used to hold information about Newsgroup articles }
  45.   PNewsGroupArticleRecord = ^TNewsGroupArticleRecord;
  46.   TNewsGroupArticleRecord = record
  47.     NGAGroupname   : String;  { Newsgroup name (redundancy safeguard)     }
  48.     NGASubject     : String;  { Subject of article                        }
  49.     NGANumber      : Longint; { Article number                            }
  50.     NGADownloaded  : boolean; { Article attempted/succeeded downloading   }
  51.     NGASender      : String;  { Article's putative sender (CIUPKC158=us)  }
  52.     NGARead        : Boolean; { Article read flag                         }
  53.     NGAPosted      : Boolean; { Article posted flag                       }
  54.     NGAArtFileName : String;  { Name of system-gen file with article text }
  55.   end;
  56.   NGARFile = file of TNewsGroupArticleRecord;
  57.   { This record is used to hold information about EMail Mailboxes }
  58.   PEMailMailBoxRecord = ^TEMailMailBoxRecord;
  59.   TEMailMailBoxRecord = record
  60.     MBName        : String;  { Name of the mailbox                     }
  61.     MBIDNumber    : Integer;
  62.     MBMaxMsgNumber : Longint;
  63.     MBTotal       : Longint; { Total Mail Messages in Mailbox          }
  64.     MBUnReadTotal : Longint; { Total unread Mail Messages in Mailbox   }
  65.     MBUnSentTotal : Longint; { Total unsent Mail Messages in Mailbox   }
  66.     MBMsgFileName : String;  { Name of file holding Messages records   }
  67.     MBLTag        : Longint; { Tag to pointer to Tlist holding msgrecs }
  68.   end;
  69.   EMMBRFile = file of TEMailMailBoxRecord; { File type for EMMBRec }
  70.   { This record is used to hold information about EMail messages in a Mailbox }
  71.   PEMailMessageRecord = ^TEMailMessageRecord;
  72.   TEMailMessageRecord = record
  73.     MRMailBoxName      : String;  { Name of mailbox (redundancy safeguard)       }
  74.     MRMessageSubject   : String;  { Subject of the Message                       }
  75.     MRMessageRecipient : String;  { EMail address of primary recipient           }
  76.     MRMessageSender    : String;  { EMail address of sender                      }
  77.     MRCarbonCopy       : String;  { EMail CC recips; "|" delimited               }
  78.     MRBlindCarbonCopy  : String;  { EMail BCC recips; "|" delimited              }
  79.     MRDateTime         : String;  { EMail date/time field                        }
  80.     MRRead             : Boolean; { EMail Read flag                              }
  81.     MRSent             : Boolean; { EMail Send flag                              }
  82.     MRFileName         : String;  { EMail system generated filename for msg text }
  83.   end;
  84.   EMMRFile = file of TEMailMessageRecord; { File type for EMMRec }
  85.   TCCINetCCForm = class(TForm)
  86.     MainMenu1: TMainMenu;
  87.     Network1: TMenuItem;
  88.     N1: TMenuItem;
  89.     Exit1: TMenuItem;
  90.     Services1: TMenuItem;
  91.     IPAddress1: TMenuItem;
  92.     EMail1: TMenuItem;
  93.     FTP1: TMenuItem;
  94.     UsenetNws1: TMenuItem;
  95.     Panel1: TPanel;
  96.     Panel2: TPanel;
  97.     Panel3: TPanel;
  98.     Panel4: TPanel;
  99.     Panel5: TPanel;
  100.     Panel6: TPanel;
  101.     ListBox1: TListBox;
  102.     Panel7: TPanel;
  103.     SpeedButton1: TSpeedButton;
  104.     SpeedButton2: TSpeedButton;
  105.     ListBox2: TListBox;
  106.     ComboBox1: TComboBox;
  107.     Button1: TButton;
  108.     Memo1: TMemo;
  109.     Files1: TMenuItem;
  110.     Edit1: TMenuItem;
  111.     Encoding1: TMenuItem;
  112.     EMail2: TMenuItem;
  113.     FTP2: TMenuItem;
  114.     News1: TMenuItem;
  115.     Load1: TMenuItem;
  116.     Save1: TMenuItem;
  117.     Cut1: TMenuItem;
  118.     Copy1: TMenuItem;
  119.     CopytoFile1: TMenuItem;
  120.     Paste1: TMenuItem;
  121.     PastefromFile1: TMenuItem;
  122.     UUDecode1: TMenuItem;
  123.     MIMEDecode1: TMenuItem;
  124.     UUEncode1: TMenuItem;
  125.     MIMEEncode1: TMenuItem;
  126.     CheckMail1: TMenuItem;
  127.     ReplyToCurrentMessage1: TMenuItem;
  128.     SendCurrentMessage1: TMenuItem;
  129.     SendQueue1: TMenuItem;
  130.     Mailboxes1: TMenuItem;
  131.     Correspondents1: TMenuItem;
  132.     EmptyTrash1: TMenuItem;
  133.     SpeedButton4: TSpeedButton;
  134.     SpeedButton5: TSpeedButton;
  135.     SpeedButton3: TSpeedButton;
  136.     Panel8: TPanel;
  137.     Label1: TLabel;
  138.     Label2: TLabel;
  139.     ComboBox2: TComboBox;
  140.     Label3: TLabel;
  141.     ComboBox3: TComboBox;
  142.     ConnectToSite1: TMenuItem;
  143.     Disconnect1: TMenuItem;
  144.     UploadMarked1: TMenuItem;
  145.     DownloadMarked1: TMenuItem;
  146.     Directory1: TMenuItem;
  147.     ASCII1: TMenuItem;
  148.     Binary1: TMenuItem;
  149.     ASCII2: TMenuItem;
  150.     Binary2: TMenuItem;
  151.     ViewRemoteasText1: TMenuItem;
  152.     FTPSites1: TMenuItem;
  153.     CheckNewNews1: TMenuItem;
  154.     GetMarked1: TMenuItem;
  155.     CreateNewMessage1: TMenuItem;
  156.     Article1: TMenuItem;
  157.     SubscribedNewsgroups1: TMenuItem;
  158.     Trash1: TMenuItem;
  159.     Preferences1: TMenuItem;
  160.     EMail3: TMenuItem;
  161.     FTP3: TMenuItem;
  162.     News2: TMenuItem;
  163.     Label4: TLabel;
  164.     Label5: TLabel;
  165.     ViewasText1: TMenuItem;
  166.     Change1: TMenuItem;
  167.     Create1: TMenuItem;
  168.     Delete3: TMenuItem;
  169.     ChangeLocal1: TMenuItem;
  170.     OpenDialog1: TOpenDialog;
  171.     SaveDialog1: TSaveDialog;
  172.     Paths1: TMenuItem;
  173.     ProgressInfo1: TMenuItem;
  174.     N2: TMenuItem;
  175.     ViewInEditWindow1: TMenuItem;
  176.     ViewInStatusLine1: TMenuItem;
  177.     SaveToFile1: TMenuItem;
  178.     ViewWinsockInfo1: TMenuItem;
  179.     Description1: TMenuItem;
  180.     SystemStatus1: TMenuItem;
  181.     VendorSpecific1: TMenuItem;
  182.     Gauge1: TGauge;
  183.     NewsServers1: TMenuItem;
  184.     AllReadArticles1: TMenuItem;
  185.     AllMarkedArticles1: TMenuItem;
  186.     AllAvailableArticles1: TMenuItem;
  187.     NewArticle1: TMenuItem;
  188.     FollowupArticle1: TMenuItem;
  189.     Post1: TMenuItem;
  190.     CurrentArticle1: TMenuItem;
  191.     EntireQueue1: TMenuItem;
  192.     ConnectandUpdate1: TMenuItem;
  193.     Disconnect2: TMenuItem;
  194.     Headers1: TMenuItem;
  195.     RetrieveMarked1: TMenuItem;
  196.     RetrieveAll1: TMenuItem;
  197.     DownloadActiveNewsgroups1: TMenuItem;
  198.     PutinQueue1: TMenuItem;
  199.     TrashMarkedMessages1: TMenuItem;
  200.     MailServers1: TMenuItem;
  201.     ExitEMailRequired1: TMenuItem;
  202.     ToCurrentMessage1: TMenuItem;
  203.     ToNewMessage1: TMenuItem;
  204.     ToFile2: TMenuItem;
  205.     AbortNewsgroupDownload1: TMenuItem;
  206.     Catchup1: TMenuItem;
  207.     Marked1: TMenuItem;
  208.     All1: TMenuItem;
  209.     File1: TMenuItem;
  210.     SelectedArticle1: TMenuItem;
  211.     SelectMultipleArticles1: TMenuItem;
  212.     DecodeSelections1: TMenuItem;
  213.     procedure Exit1Click(Sender: TObject);
  214.     procedure FormCreate(Sender: TObject);
  215.     procedure FormDestroy(Sender: TObject);
  216.     procedure Description1Click(Sender: TObject);
  217.     procedure SystemStatus1Click(Sender: TObject);
  218.     procedure VendorSpecific1Click(Sender: TObject);
  219.     procedure ViewInEditWindow1Click(Sender: TObject);
  220.     procedure ViewInStatusLine1Click(Sender: TObject);
  221.     procedure SaveToFile1Click(Sender: TObject);
  222.     procedure IPAddress1Click(Sender: TObject);
  223.     procedure FTP1Click(Sender: TObject);
  224.     procedure FormResize(Sender: TObject);
  225.     procedure FTPSites1Click(Sender: TObject);
  226.     procedure FTP3Click(Sender: TObject);
  227.     procedure ConnectToSite1Click(Sender: TObject);
  228.     procedure Button1Click(Sender: TObject);
  229.     procedure ViewasText1Click(Sender: TObject);
  230.     procedure Disconnect1Click(Sender: TObject);
  231.     procedure ToDisplay1Click(Sender: TObject);
  232.     procedure ToFile1Click(Sender: TObject);
  233.     procedure Binary2Click(Sender: TObject);
  234.     procedure Change1Click(Sender: TObject);
  235.     procedure ChangeLocal1Click(Sender: TObject);
  236.     procedure ListBox1DblClick(Sender: TObject);
  237.     procedure ListBox2DblClick(Sender: TObject);
  238.     procedure ASCII1Click(Sender: TObject);
  239.     procedure DeleteRemoteFiles1Click(Sender: TObject);
  240.     procedure Binary1Click(Sender: TObject);
  241.     procedure Delete3Click(Sender: TObject);
  242.     procedure Create1Click(Sender: TObject);
  243.     procedure ListBox1Click(Sender: TObject);
  244.     procedure UsenetNws1Click(Sender: TObject);
  245.     procedure Disconnect2Click(Sender: TObject);
  246.     procedure News2Click(Sender: TObject);
  247.     procedure ConnectandUpdate1Click(Sender: TObject);
  248.     procedure CheckNewNews1Click(Sender: TObject);
  249.     procedure NewsServers1Click(Sender: TObject);
  250.     procedure SubscribedNewsgroups1Click(Sender: TObject);
  251.     procedure RetrieveMarked1Click(Sender: TObject);
  252.     procedure RetrieveAll1Click(Sender: TObject);
  253.     procedure GetMarked1Click(Sender: TObject);
  254.     procedure NewArticle1Click(Sender: TObject);
  255.     procedure FollowupArticle1Click(Sender: TObject);
  256.     procedure PutinQueue1Click(Sender: TObject);
  257.     procedure CurrentArticle1Click(Sender: TObject);
  258.     procedure EntireQueue1Click(Sender: TObject);
  259.     procedure AllReadArticles1Click(Sender: TObject);
  260.     procedure AllMarkedArticles1Click(Sender: TObject);
  261.     procedure AllAvailableArticles1Click(Sender: TObject);
  262.     procedure DownloadActiveNewsgroups1Click(Sender: TObject);
  263.     procedure UUEncode1Click(Sender: TObject);
  264.     procedure Load1Click(Sender: TObject);
  265.     procedure Save1Click(Sender: TObject);
  266.     procedure EMail1Click(Sender: TObject);
  267.     procedure CheckMail1Click(Sender: TObject);
  268.     procedure CreateNewMessage1Click(Sender: TObject);
  269.     procedure ReplyToCurrentMessage1Click(Sender: TObject);
  270.     procedure SendCurrentMessage1Click(Sender: TObject);
  271.     procedure SendQueue1Click(Sender: TObject);
  272.     procedure MailServers1Click(Sender: TObject);
  273.     procedure Mailboxes1Click(Sender: TObject);
  274.     procedure Correspondents1Click(Sender: TObject);
  275.     procedure EMail3Click(Sender: TObject);
  276.     procedure Paths1Click(Sender: TObject);
  277.     procedure ExitEMailRequired1Click(Sender: TObject);
  278.     procedure TrashMarkedMessages1Click(Sender: TObject);
  279.     procedure EmptyTrash1Click(Sender: TObject);
  280.     procedure ComboBox2Change(Sender: TObject);
  281.     procedure ComboBox3Change(Sender: TObject);
  282.     procedure MIMEDecode1Click(Sender: TObject);
  283.     procedure Cut1Click(Sender: TObject);
  284.     procedure Copy1Click(Sender: TObject);
  285.     procedure CopytoFile1Click(Sender: TObject);
  286.     procedure Paste1Click(Sender: TObject);
  287.     procedure PastefromFile1Click(Sender: TObject);
  288.     procedure SpeedButton5Click(Sender: TObject);
  289.     procedure SpeedButton3Click(Sender: TObject);
  290.     procedure SpeedButton1Click(Sender: TObject);
  291.     procedure SpeedButton2Click(Sender: TObject);
  292.     procedure ListBox2Click(Sender: TObject);
  293.     procedure AbortNewsgroupDownload1Click(Sender: TObject);
  294.     procedure Marked1Click(Sender: TObject);
  295.     procedure All1Click(Sender: TObject);
  296.     procedure File1Click(Sender: TObject);
  297.     procedure SelectedArticle1Click(Sender: TObject);
  298.     procedure SelectMultipleArticles1Click(Sender: TObject);
  299.     procedure DecodeSelections1Click(Sender: TObject);
  300.     procedure SpeedButton4Click(Sender: TObject);
  301.   private
  302.     { Private declarations }
  303.   public
  304.     { Public declarations }
  305.     procedure EnableFTPMenus;
  306.     procedure DisableFTPMenus;
  307.     procedure EnableNNTPMenus;
  308.     procedure DisableNNTPMenus;
  309.     procedure EnablePOP3SMTPMenus;
  310.     procedure DisablePOP3SMTPMenus;
  311.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  312.     procedure UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  313.     procedure UpdateMIMEGauge( BytesFinished , TotalToHandle : longint );
  314.     procedure UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  315.     function DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  316.     function DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  317.     function DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  318.     function DoSMTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  319.     procedure DoFTPDisconnect;
  320.     procedure DoNNTPDisconnect;
  321.     procedure DoPOP3SMTPDisconnect;
  322.     procedure ReadIniData;
  323.     procedure WriteIniData;
  324.     procedure LoadFTPSiteFile;
  325.     procedure LoadNNTPSiteFile;
  326.     procedure LoadEmailServerFile;
  327.     procedure SaveEMailServerFile;
  328.     procedure LoadEmailMailboxFile( WhichServer : Integer );
  329.     procedure SaveEMailMailboxFile( WhichServer : Integer );
  330.     procedure LoadEmailCorrespondentsFile;
  331.     procedure SaveEMailCorrespondentsFile;
  332.     procedure SetupEMailServerStatus;
  333.     procedure SetupNNTPServersInfoDisplay;
  334.     procedure SaveFTPSiteFile;
  335.     procedure SetupFTPSiteLists;
  336.     procedure SaveNNTPSiteFile;
  337.     procedure SetupNNTPSiteLists;
  338.     procedure SetupNNTPNewsGroupsInfoDisplay;
  339.     procedure SetupNNTPNewsGroupLists;
  340.     procedure SaveNNTPNewsGroupLists;
  341.     procedure SetupNewsGroupListboxes;
  342.     procedure SetupEMailListboxes;
  343.     procedure SetupMailboxLists;
  344.     procedure SetupEMailServersInfoDisplay;
  345.     procedure SetupEMailMailboxInfoDisplay;
  346.     procedure PopulateLB2WithArticleHeaders;
  347.     procedure PopulateLB2WithMessageHeaders;
  348.     procedure SetupEMailCorrespondentsInfoDisplay;
  349.     procedure AddNullTermTextToMemo( TheTextToAdd   : String;
  350.                                      TheMemoToAddTo : TMemo   );
  351.     function AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  352.     procedure SetHGCursors;
  353.     procedure SetNormalCursors;
  354.     procedure AddProgressText( WhatText : String );
  355.     procedure ShowProgressText( WhatText : String );
  356.     procedure ShowProgressErrorText( WhatText : String );
  357.     procedure SocketsErrorOccurred( Sender     : TObject;
  358.                                      ErrorCode  : Integer;
  359.                                      TheMessage : String   );
  360.   end;
  361.   { Component to hold FTP handling capabilities }
  362.   TFTPComponent = class( TWinControl )
  363.   public
  364.     FTPCommandInProgress ,
  365.     Connection_Established : Boolean;
  366.     Socket1 : TCCSocket;
  367.     Socket2 : TCCSocket;
  368.     constructor Create( AOwner : TComponent ); override;
  369.     destructor Destroy; override;
  370.     function GetTotalBytesToReceive( TheString : String ) : Longint;
  371.     function StripBrackets( TheString : String ) : String;
  372.     function GetShortPathname( TheString : String ) : String;
  373.     function GetWin16FileName( InputName : String ) : String;
  374.     function GetRemoteWorkingDirectory( var RemoteDir : String ) : Boolean;
  375.     function SetRemoteDirectory( TheDir : String ) : Boolean;
  376.     function DeleteRemoteDirectory( TheDir : String ) : Boolean;
  377.     function CreateRemoteDirectory( TheDir : String ) : Boolean;
  378.     function DeleteRemoteFile( TheFileName : String ) : Boolean;
  379.     function EstablishConnection( PCRPointer : PConnectionsRecord ) : Boolean;
  380.     function LoginUser( PCRPointer : PConnectionsRecord ) : Boolean;
  381.     function SendPassword( PCRPointer : PConnectionsRecord ) : Boolean;
  382.     function SetRemoteStartupDirectory( PCRPointer : PConnectionsRecord )
  383.               : Boolean;
  384.     function GetRemoteDirectoryListing( TheListBox : TListBox ) : Boolean;
  385.     function GetRemoteDirectoryListingToMemo : Boolean;
  386.     procedure SendASCIILocalFile( LocalName : String );
  387.     procedure SendBinaryLocalFile( LocalName : String );
  388.     procedure ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  389.     procedure ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  390.     function GetLocalDirectoryAndListing( var TheString : String;
  391.                                               TheListBox : TListBox )
  392.               : Boolean;
  393.     function GetUNIXTextString( var StringIn : String ) : String;
  394.     procedure ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  395.     function GetListeningPort : Integer;
  396.     procedure GetFileNameFromUNIXFileName( var TheName : String );
  397.     function Disconnect : Boolean;
  398.     function DoCStyleFormat(       TheText      : string;
  399.                              const TheArguments : array of const ) : String;
  400.     procedure UpdateGauge( BytesFinished , TotalToHandle : longint );
  401.     function GetQuotedString( TheString : String ) : String;
  402.     procedure AddProgressText( WhatText : String );
  403.     procedure ShowProgressText( WhatText : String );
  404.     procedure ShowProgressErrorText( WhatText : String );
  405.     function GetFTPServerResponse( var ResponseString : String ) : integer;
  406.     procedure FTPSocketsErrorOccurred( Sender     : TObject;
  407.                                      ErrorCode  : Integer;
  408.                                      TheMessage : String   );
  409.     function PerformFTPCommand(
  410.                     TheCommand   : string;
  411.               const TheArguments : array of const ) : Integer;
  412.   end;
  413. const
  414.   POV_MEMO                 = 1; { Progress to the Memo           }
  415.   POV_STAT                 = 2; { Progress to the status caption }
  416.   TCPIP_STATUS_PRELIMINARY   = 1; { Wait; command being processed  }
  417.   TCPIP_STATUS_COMPLETED     = 2; { Done; command fully succeded   }
  418.   TCPIP_STATUS_CONTINUING    = 3; { OK; send more data to finish   }
  419.   TCPIP_STATUS_RETRY_COMMAND = 4; { Temporary Error; try cmd again }
  420.   TCPIP_STATUS_FATAL_ERROR   = 5; { Fatal Error; don't retry cmd   }
  421.  
  422. var
  423.   CCINetCCForm         : TCCINetCCForm;
  424.   GlobalErrorCode      : Integer;        { Used to pass around error info  }
  425.   GlobalAbortedFlag    : Boolean;        { Used to signal timeout error    }
  426.   ProgressList         : TStringList;    { Used to hold progress text info }
  427.   ProgressFileName     : String;         { Used to hold progress file name }
  428.   ProgressOutputVector : Integer;        { Used to direct progress output  }
  429.   TheFTPSiteList       : TList;          { Used to store the FTP site recs }
  430.   TheWorkingFTPSL      : TList;          { Used to store working copy of l }
  431.   TheNewsServerList    : TList;          { Used to hold list of NNTP servs }
  432.   TheWorkingNSSL       : TList;          { Used for working copy of above  }
  433.   TheEMailServerList   : TList;          { Used for list of POP3/SMTP serv }
  434.   TheWorkingEMSL       : TList;          { Used for working copy of above  }
  435.   TheNewsRCList        : TList;          { Used for list of available ngs  }
  436.   TheWorkingNRCSL      : TList;          { Used for working copy of above  }
  437.   TheNGArticlesList    : TList;          { Used for current articles list  }
  438.                                          { (will hot swap from pointer of  }
  439.                                          {  Tlist of Tlists in base rec.)  }
  440.   TheEMailMailboxList  : TList;          { Used for list of available mbs  }
  441.   TheWorkingMBSL       : TList;          { Used for working copy of above  }
  442.   TheCorrespondentsList: TList;          { Used for list of correspondents }
  443.   TheWorkingCPSL       : TList;          { Used for working copy of above  }
  444.   TheMBMessagesList    : TList;          { Used for current msgs; hotswaps }
  445.   TheEMailServerFile   : CRFile;         { File of Email servers records   }
  446.   TheEMailCorrespondentsFile : CRFile;
  447.   TheNewsServerFile    : CRFile;         { File of NNTP servers records    }
  448.   TheNewsRCFile        : NGRFile;        { File of Newsgroups records      }
  449.   TheNewsArticleFile   : NGARFile;       { Current ng articles records file}
  450.   TheEMailMailboxFile  : EMMBRFile;      { File of Mailboxes records       }
  451.   TheEMailMessagesFile : EMMRFile;       { Current mb messages records file}
  452.   TheFTPSiteFile       : CRFile;         { Used to load the FTP site file  }
  453.   TheICCIniFile        : TIniFile;       { Used to retrieve the INI File   }
  454.   MailPath             : String;         { Used for path to Mail Files     }
  455.   NewsPath             : String;         { Used for path to News Files     }
  456.   FTPPath              : String;         { Used for path to FTP Files      }
  457.   CurrentPassWordString : String;        { Used to hold login id for anons }
  458.   CurrentEMPassWordString : String;      { Used to hold login id for anons }
  459.   PassWordControlVector : Integer;       { Used to hold display of pw vect }
  460.   CurrentRealPWString   : String;        { Used to hold a real password    }
  461.   EMPassWordControlVector : Integer;       { Used to hold display of pw vect }
  462.   CurrentEMRealPWString   : String;        { Used to hold a real password    }
  463.   TheFTPComponent       : TFTPComponent; { FTP Object                      }
  464.   TheLine ,
  465.   HolderLine ,
  466.   GlobalTextBuffer      : String;
  467.   TheAnonRedialVector ,
  468.   DefaultDownloadVector : Integer;
  469.   NewsReadArticlePurgingVector : Integer;
  470.   NewsPostQueueingVector : Integer;
  471.   NewsReadArticleDisplayVector : Integer;
  472.   NewsUUMIMEVector : Integer;
  473.   NewsInitialUpdateVector : Integer;
  474.   LeftoverText          : String;
  475.   LeftoversOnTable      : Boolean;
  476.   FileNameToXFer        : String;
  477.   WhichServer           : Integer;       { Holds current NNTP server }
  478.   WhichGroup            : Integer;       { Holds current NNTP newsgroup }
  479.   TheUUObject           : TUUCodingObject;
  480.   EMRemoteDeletionVector : Integer;
  481.   EMChokeVector : Integer;
  482.   EMDefaultDownloadVector : Integer;
  483.   EMQueueVector : Integer;
  484.   NewsgroupListLoaded ,
  485.   EmailLoaded ,
  486.   NewMessageInProgress : Boolean;
  487.   TheUUDecodeList      : TStringList;
  488.   
  489. implementation
  490.  
  491. uses CCICCPOP, CCICNNTP;
  492.  
  493. var
  494.   TheNNTPComponent      : TNNTPComponent;{ NNTP News Object                }
  495.  
  496. {$R *.DFM}
  497.  
  498.  
  499. { This procedure actually attempts to connect to the internet at an POP3SMTP site }
  500. function TCCINetCCForm.DoPOP3Connection( PCRPointer : PConnectionsRecord ) : boolean;
  501. begin
  502.   { Create the component }
  503.   Result := false;
  504.   { Do busy cursors }
  505.   SetHGCursors;
  506.   if not ThePOP3SMTPComponent.EstablishPOP3Connection( PCRPointer ) then
  507.   begin
  508.     { Do saved cursors }
  509.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  510.     ThePOP3SMTPComponent.Connection_Established := false;
  511.     SetNormalCursors;
  512.     exit;
  513.   end;
  514.   if not ThePOP3SMTPComponent.LoginUser( PCRPointer ) then
  515.   begin
  516.     { Do saved cursors }
  517.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  518.     ThePOP3SMTPComponent.Connection_Established := false;
  519.     SetNormalCursors;
  520.     exit;
  521.   end;
  522.   if not ThePOP3SMTPComponent.SendPassword( PCRPointer ) then
  523.   begin
  524.     { Do saved cursors }
  525.     ThePOP3SMTPComponent.POP3CommandInProgress := false;
  526.     ThePOP3SMTPComponent.Connection_Established := false;
  527.     SetNormalCursors;
  528.     exit;
  529.   end;
  530.   SetNormalCursors;
  531.   Result := true;
  532.   EnablePOP3SMTPMenus;
  533.   ThePOP3SMTPComponent.POP3CommandInProgress := false;
  534.   Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  535. end;
  536.  
  537. { This procedure actually attempts to connect to the internet at an POP3SMTP site }
  538. function TCCINetCCForm.DoSMTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  539. begin
  540.   { Create the component }
  541.   Result := false;
  542.   { Do busy cursors }
  543.   SetHGCursors;
  544.   if not ThePOP3SMTPComponent.EstablishSMTPConnection( PCRPointer ) then
  545.   begin
  546.     { Do saved cursors }
  547.     ThePOP3SMTPComponent.SMTPCommandInProgress := false;
  548.     ThePOP3SMTPComponent.Connection_Established := false;
  549.     SetNormalCursors;
  550.     exit;
  551.   end;
  552.   if not ThePOP3SMTPComponent.SendHelo( PCRPointer ) then
  553.   begin
  554.     { Do saved cursors }
  555.     ThePOP3SMTPComponent.SMTPCommandInProgress := false;
  556.     ThePOP3SMTPComponent.Connection_Established := false;
  557.     SetNormalCursors;
  558.     exit;
  559.   end;
  560.   SetNormalCursors;
  561.   Result := true;
  562.   ThePOP3SMTPComponent.SMTPCommandInProgress := false;
  563.   Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  564. end;
  565.  
  566. { This procedure actually attempts to disconnect to the internet at an ftp site}
  567. procedure TCCINetCCForm.DoPOP3SMTPDisconnect;
  568. begin
  569.   { Kill the socket }
  570.   ThePOP3SMTPComponent.Socket1.CCSockClose;
  571.   ThePOP3SMTPComponent.Connection_Established := false;
  572. end;
  573.  
  574. { Procedure to load the POP3SMTP Site list }
  575. procedure TCCINetCCForm.LoadEmailServerFile;
  576. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  577.     PSSLName     : String;             { POP3SMTP Site List filename }
  578.     Counter_1    : Integer;            { Loop counter           }
  579. begin
  580.   { Create the sites list list }
  581.   TheEMailServerList := TList.Create;
  582.   { Set up the FTP sites list file name }
  583.   PSSLName := MailPath + '\PSSERVER.TCR';
  584.   { If the FTP Site List exists load it in }
  585.   if FileExists( PSSLName ) then
  586.   begin
  587.     { set up the file and open it }
  588.     AssignFile( TheEMailServerFile , PSSLName );
  589.     Reset( TheEMailServerFile );
  590.     { read in the records }
  591.     for Counter_1 := 0 to FileSize( TheEMailServerFile ) - 1 do
  592.     begin
  593.       { Create the TCRecord }
  594.       New( ThePSSRecord );
  595.       { Read in the data record }
  596.       Seek( TheEMailServerFile , Counter_1 );
  597.       Read( TheEMailServerFile , ThePSSRecord^ );
  598.       { Add the record to the list }
  599.       TheEMailServerList.Add( ThePSSRecord );
  600.     end;
  601.     { close the file }
  602.     CloseFile( TheEMailServerFile );
  603.   end
  604.   else
  605.   { Otherwise create a default one with the a generic mail site (?) }
  606.   begin
  607.     { create new record }
  608.     New( ThePSSRecord );
  609.     { fill in its info }
  610.     with ThePSSRecord^ do
  611.     begin
  612.       CProfile   := 'My Mail Server';
  613.       CIPAddress := 'mail.myprovider.com';
  614.       CUserName  := 'myname';
  615.       CPassword  := 'mypassword';
  616.       CStartDir  := 'myname@myprovider.com';
  617.     end;
  618.     { add it to the list }
  619.     { do it three more times }
  620.     TheEMailServerList.Add( ThePSSRecord );
  621.     { create the file and write out the data, then close it }
  622.     AssignFile( TheEMailServerFile , PSSLName );
  623.     Rewrite( TheEMailServerFile );
  624.     ThePSSRecord :=
  625.        PConnectionsRecord( TheEMailServerList.Items[ 0 ] );
  626.       Seek( TheEMailServerFile , 0 );
  627.       Write( TheEMailServerFile , ThePSSRecord^ );
  628.     CloseFile( TheEMailServerFile );
  629.   end;
  630.   TheWorkingEMSL := TList.Create;
  631.   For Counter_1 := 0 to TheEMailServerList.Count - 1 do
  632.   begin
  633.     New( ThePSSRecord );
  634.     ThePSSRecord^ := PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] )^;
  635.     TheWorkingEMSL.Add( ThePSSRecord );
  636.   end;
  637. end;
  638.  
  639. procedure TCCINetCCForm.SaveEMailServerFile;
  640. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  641.     PSSLName     : String;             { POP3SMTP Site List filename }
  642.     Counter_1    : Integer;            { Loop counter           }
  643. begin
  644.   { Set up the file name }
  645.   PSSLName := MailPath + '\PSSERVER.TCR';
  646.   { Assign the file }
  647.   AssignFile( TheEMailServerFile , PSSLName );
  648.   { Rewrite it }
  649.   Rewrite( TheEMailServerFile );
  650.   { run the list through the procedure }
  651.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  652.   begin
  653.     { get the record from the list }
  654.     ThePSSRecord :=
  655.      PConnectionsRecord( TheEMailServerList.Items[ Counter_1 ] );
  656.     { Do the seek/write }
  657.     Seek( TheEMailServerFile , Counter_1 );
  658.     Write( TheEMailServerFile , ThePSSRecord^ );
  659.     { free the record }
  660.     Dispose( ThePSSRecord );
  661.   end;
  662.   { Close the file }
  663.   CloseFile( TheEMailServerFile );
  664.   { Free the list pointers }
  665.   TheEMailServerList.Free;
  666.   for Counter_1 := 0 to TheWorkingEMSL.Count - 1 do
  667.   begin
  668.     ThePSSRecord := PConnectionsRecord( TheWorkingEMSL.Items[ Counter_1 ] );
  669.     Dispose( ThePSSRecord );
  670.   end;
  671.   TheWorkingEMSL.Free;
  672. end;
  673.  
  674. { Procedure to load the POP3SMTP Site list }
  675. procedure TCCINetCCForm.LoadEmailMailboxFile( WhichServer : Integer );
  676. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  677.     PSMBName    : String;              { Mailbox filename       }
  678.     Counter_1   ,
  679.     Counter_2   : Integer;             { Loop counter           }
  680.     TheMessagesList : TList;
  681.     TheEMMRecord : PEMailMessageRecord;
  682. begin
  683.   { Create the sites list list }
  684.   TheEMailMailboxList := TList.Create;
  685.   { Set up the FTP sites list file name }
  686.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  687.   { If the FTP Site List exists load it in }
  688.   if FileExists( PSMBName ) then
  689.   begin
  690.     { set up the file and open it }
  691.     AssignFile( TheEMailMailboxFile , PSMBName );
  692.     Reset( TheEMailMailboxFile );
  693.     { read in the records }
  694.     for Counter_1 := 0 to FileSize( TheEMailMailboxFile ) - 1 do
  695.     begin
  696.       { Create the TCRecord }
  697.       New( TheMBRecord );
  698.       { Read in the data record }
  699.       Seek( TheEMailMailboxFile , Counter_1 );
  700.       Read( TheEMailMailboxFile , TheMBRecord^ );
  701.       { Add the record to the list }
  702.       TheEMailMailboxList.Add( TheMBRecord );
  703.     end;
  704.     { close the file }
  705.     CloseFile( TheEMailMailboxFile );
  706.   end
  707.   else
  708.   { Otherwise create a default one with the In and Out mailboxes (?) }
  709.   begin
  710.     { create new record }
  711.     New( TheMBRecord );
  712.     { fill in its info }
  713.     with TheMBRecord^ do
  714.     begin
  715.       MBName         := 'In Box';
  716.       MBIDNumber     := 1;
  717.       MBMaxMsgNumber := 0;
  718.       MBTotal        := 0;
  719.       MBUnReadTotal  := 0;
  720.       MBUnSentTotal  := 0;
  721.       MBMsgFileName  := 'MB1.MBX';
  722.       MBLTag         := 0;
  723.     end;
  724.     { add it to the list }
  725.     TheEMailMailboxList.Add( TheMBRecord );
  726.     { create new record }
  727.     New( TheMBRecord );
  728.     { fill in its info }
  729.     with TheMBRecord^ do
  730.     begin
  731.       MBName         := 'Out Box';
  732.       MBIDNumber     := 2;
  733.       MBMaxMsgNumber := 0;
  734.       MBTotal        := 0;
  735.       MBUnReadTotal  := 0;
  736.       MBUnSentTotal  := 0;
  737.       MBMsgFileName  := 'MB2.MBX';
  738.       MBLTag         := 0;
  739.     end;
  740.     { add it to the list }
  741.     TheEMailMailboxList.Add( TheMBRecord );
  742.     { create the file and write out the data, then close it }
  743.     AssignFile( TheEMailMailboxFile , PSMBName );
  744.     Rewrite( TheEMailMailboxFile );
  745.     TheMBRecord :=
  746.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  747.       Seek( TheEMailMailboxFile , 0 );
  748.       Write( TheEMailMailboxFile , TheMBRecord^ );
  749.     TheMBRecord :=
  750.        PEMailMailboxRecord( TheEMailMailboxList.Items[ 1 ] );
  751.       Seek( TheEMailMailboxFile , 1 );
  752.       Write( TheEMailMailboxFile , TheMBRecord^ );
  753.     CloseFile( TheEMailMailboxFile );
  754.   end;
  755.   { Load in Message Records and create storage lists }
  756.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  757.   begin
  758.     PSMBName := PEMailMailboxRecord(
  759.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  760.     if FileExists( MailPath + '\' + PSMBName ) then
  761.     begin
  762.       TheMessagesList := TList.Create;
  763.       AssignFile( TheEMailMessagesFile , MailPath + '\' + PSMBName );
  764.       Reset( TheEMailMessagesFile );
  765.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  766.       begin
  767.         New( TheEMMRecord );
  768.         Seek( TheEMailMessagesFile , Counter_2 );
  769.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  770.         TheMessagesList.Add( TheEMMRecord );
  771.       end;
  772.       CloseFile( TheEMailMessagesFile );
  773.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  774.        Longint( TheMessagesList );
  775.     end
  776.     else
  777.     begin
  778.       TheMessagesList := TList.Create;
  779.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  780.        Longint( TheMessagesList );
  781.     end;
  782.   end;
  783.   TheWorkingMBSL := TList.Create;
  784.   For Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  785.   begin
  786.     New( TheMBRecord );
  787.     TheMBRecord^ := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^;
  788.     TheWorkingMBSL.Add( TheMBRecord );
  789.   end;
  790. end;
  791.  
  792. procedure TCCINetCCForm.SaveEMailMailboxFile( WhichServer : Integer );
  793. var TheMBRecord : PEMailMailboxRecord; { Generic TCR Pointer    }
  794.     PSMBName    : String;              { Mailbox filename       }
  795.     Counter_2 ,
  796.     Counter_1   : Integer;             { Loop counter           }
  797.     TheList     : TList;
  798.     TheEMMRecord : PEMailMessageRecord;
  799. begin
  800.   { Load in Message Records and create storage lists }
  801.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  802.   begin
  803.     PSMBName := PEMailMailboxRecord(
  804.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  805.     TheList := TList( PEMailMailboxRecord(
  806.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag );
  807.     AssignFile( TheEMailMessagesFile , Mailpath + '\' + PSMBName );
  808.     Rewrite( TheEMailMessagesFile );
  809.     for Counter_2 := 0 to TheList.Count - 1 do
  810.     begin
  811.       TheEMMRecord := PEMailMessageRecord( TheList.Items[ Counter_2 ] );
  812.       Seek( TheEMailMessagesFile , Counter_2 );
  813.       Write( TheEMailMessagesFile , TheEMMRecord^ );
  814.       Dispose( TheEMMRecord );
  815.     end;
  816.     CloseFile( TheEMailMessagesFile );
  817.     TheList.Free;
  818.   end;
  819.   { Set up the file name }
  820.   PSMBName := MailPath + '\MAILBX' + IntToStr( WhichServer ) + '.MBX';
  821.   { Assign the file }
  822.   AssignFile( TheEMailMailboxFile , PSMBName );
  823.   { Rewrite it }
  824.   Rewrite( TheEMailMailboxFile );
  825.   { run the list through the procedure }
  826.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  827.   begin
  828.     { get the record from the list }
  829.     TheMBRecord :=
  830.      PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  831.     { Do the seek/write }
  832.     Seek( TheEMailMailboxFile , Counter_1 );
  833.     Write( TheEMailMailboxFile , TheMBRecord^ );
  834.     { free the record }
  835.     Dispose( TheMBRecord );
  836.   end;
  837.   { Close the file }
  838.   CloseFile( TheEMailMailboxFile );
  839.   { Free the list pointers }
  840.   TheEMailMailboxList.Free;
  841.   for Counter_1 := 0 to TheWorkingMBSL.Count - 1 do
  842.   begin
  843.     TheMBRecord := PEMailMailboxRecord( TheWorkingMBSL.Items[ Counter_1 ] );
  844.     Dispose( TheMBRecord );
  845.   end;
  846.   TheWorkingMBSL.Free;
  847. end;
  848.  
  849. { Procedure to load the POP3SMTP Site list }
  850. procedure TCCINetCCForm.LoadEmailCorrespondentsFile;
  851. var ThePSSRecord : PConnectionsRecord; { Generic TCR Pointer    }
  852.     PSSLName     : String;             { POP3SMTP Site List filename }
  853.     Counter_1    : Integer;            { Loop counter           }
  854. begin
  855.   { Create the sites list list }
  856.   TheCorrespondentsList := TList.Create;
  857.   { Set up the FTP sites list file name }
  858.   PSSLName := MailPath + '\PSCORRSP.TCR';
  859.   { If the FTP Site List exists load it in }
  860.   if FileExists( PSSLName ) then
  861.   begin
  862.     { set up the file and open it }
  863.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  864.     Reset( TheEMailCorrespondentsFile );
  865.     { read in the records }
  866.     for Counter_1 := 0 to FileSize( TheEMailCorrespondentsFile ) - 1 do
  867.     begin
  868.       { Create the TCRecord }
  869.       New( ThePSSRecord );
  870.       { Read in the data record }
  871.       Seek( TheEMailCorrespondentsFile , Counter_1 );
  872.       Read( TheEMailCorrespondentsFile , ThePSSRecord^ );
  873.       { Add the record to the list }
  874.       TheCorrespondentsList.Add( ThePSSRecord );
  875.     end;
  876.     { close the file }
  877.     CloseFile( TheEMailCorrespondentsFile );
  878.   end
  879.   else
  880.   { Otherwise create a default one with the author }
  881.   begin
  882.     { create new record }
  883.     New( ThePSSRecord );
  884.     { fill in its info }
  885.     with ThePSSRecord^ do
  886.     begin
  887.       CProfile   := 'Nathan Wallace at TDE';
  888.       CIPAddress := 'kilgalen@tde.com';
  889.       CUserName  := '';
  890.       CPassword  := '';
  891.       CStartDir  := '';
  892.     end;
  893.     { add it to the list }
  894.     { do it three more times }
  895.     TheCorrespondentsList.Add( ThePSSRecord );
  896.     { create the file and write out the data, then close it }
  897.     AssignFile( TheEMailCorrespondentsFile , PSSLName );
  898.     Rewrite( TheEMailCorrespondentsFile );
  899.     ThePSSRecord :=
  900.        PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] );
  901.       Seek( TheEMailCorrespondentsFile , 0 );
  902.       Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  903.     CloseFile( TheEMailCorrespondentsFile );
  904.   end;
  905.   TheWorkingCPSL := TList.Create;
  906.   For Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  907.   begin
  908.     New( ThePSSRecord );
  909.     ThePSSRecord^ := PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] )^;
  910.     TheWorkingCPSL.Add( ThePSSRecord );
  911.   end;
  912.   CCInetCCForm.ComboBox2.Clear;
  913.   CCInetCCForm.ComboBox3.Clear;
  914.   { Add the new info }
  915.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  916.   begin
  917.     CCINetCCForm.ComboBox2.Items.Add( PConnectionsRecord(
  918.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  919.     CCINetCCForm.ComboBox3.Items.Add( PConnectionsRecord(
  920.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  921.   end;
  922.   CCINetCCForm.ComboBox2.ItemIndex := 0;
  923.   CCINetCCForm.ComboBox3.ItemIndex := 0;
  924. end;
  925.  
  926. procedure TCCINetCCForm.SaveEMailCorrespondentsFile;
  927. var ThePSSRecord : PConnectionsRecord; { The TC Record pointer   }
  928.     PSSLName     : String;             { POP3SMTP Site List filename }
  929.     Counter_1    : Integer;            { Loop counter           }
  930. begin
  931.   { Set up the file name }
  932.   PSSLName := MailPath + '\PSCORRSP.TCR';
  933.   { Assign the file }
  934.   AssignFile( TheEMailCorrespondentsFile , PSSLName );
  935.   { Rewrite it }
  936.   Rewrite( TheEMailCorrespondentsFile );
  937.   { run the list through the procedure }
  938.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  939.   begin
  940.     { get the record from the list }
  941.     ThePSSRecord :=
  942.      PConnectionsRecord( TheCorrespondentsList.Items[ Counter_1 ] );
  943.     { Do the seek/write }
  944.     Seek( TheEMailCorrespondentsFile , Counter_1 );
  945.     Write( TheEMailCorrespondentsFile , ThePSSRecord^ );
  946.     { free the record }
  947.     Dispose( ThePSSRecord );
  948.   end;
  949.   { Close the file }
  950.   CloseFile( TheEMailCorrespondentsFile );
  951.   { Free the list pointers }
  952.   TheCorrespondentsList.Free;
  953.   for Counter_1 := 0 to TheWorkingCPSL.Count - 1 do
  954.   begin
  955.     ThePSSRecord := PConnectionsRecord( TheWorkingCPSL.Items[ Counter_1 ] );
  956.     Dispose( ThePSSRecord );
  957.   end;
  958.   TheWorkingCPSL.Free;
  959. end;
  960.  
  961. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  962. procedure TCCINetCCForm.SetupEMailServerStatus;
  963. begin
  964.   { Set up display for main form }
  965.   CCINetCCForm.Tag := 6; { Email Tag }
  966.   CCINetCCForm.Caption := 'CC Internet Command Center -- EMail Mode';
  967.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  968.   CCINetCCForm.EMail2.Enabled := true;
  969.   CCINetCCForm.EMail1.Enabled := false;
  970.   CCINetCCForm.UsenetNws1.Enabled := false;
  971.   CCINetCCForm.FTP1.Enabled := false;
  972.   CCINetCCForm.Label1.Caption := 'Mail Server:';
  973.   CCINetCCForm.Button1.Caption := 'New Mail';
  974.   CCINetCCForm.Label4.Caption := 'Mailboxes';
  975.   CCINetCCForm.Label5.Caption := 'Messages';
  976. end;
  977.  
  978. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  979. procedure TCCINetCCForm.SetupMailboxLists;
  980. var TheEMMRecord : PEMailMessageRecord; {  }
  981.     Counter_1 ,
  982.     Counter_2    : Integer;             {  }
  983.     EMMFileName  : String;              {  }
  984.     WorkingList  : TList;
  985. begin
  986.   { Abort if no server to select }
  987.   if ComboBox1.ItemIndex = -1 then exit;
  988.   { Get number of server in list }
  989.   WhichServer := ComboBox1.ItemIndex;
  990.   { Load in mailbox data }
  991.   LoadEmailMailboxFile( WhichServer );
  992.   { Load in Mailbox Records and create storage lists }
  993.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  994.   begin
  995.     EMMFileName := PEMailMailboxRecord(
  996.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBMsgFileName;
  997.     if FileExists( MailPath + '\' + EMMFileName ) then
  998.     begin
  999.       WorkingList := TList.Create;
  1000.       AssignFile( TheEMailMessagesFile , EMMFileName );
  1001.       Reset( TheEMailMessagesFile );
  1002.       for Counter_2 := 0 to FileSize( TheEMailMessagesFile ) - 1 do
  1003.       begin
  1004.         New( TheEMMRecord );
  1005.         Seek( TheEMailMessagesFile , Counter_2 );
  1006.         Read( TheEMailMessagesFile , TheEMMRecord^ );
  1007.         WorkingList.Add( TheEMMRecord );
  1008.       end;
  1009.       CloseFile( TheEMailMessagesFile );
  1010.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  1011.        Longint( WorkingList );
  1012.     end
  1013.     else
  1014.     begin
  1015.       WorkingList := TList.Create;
  1016.       PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] )^.MBLTag :=
  1017.        Longint( WorkingList );
  1018.     end;
  1019.   end;
  1020. end;
  1021.  
  1022. { This procedure populates LB2 with article subjects for any }
  1023. { available articles for a given newsgroup.                  }
  1024. procedure TCCINetCCForm.PopulateLB2WithMessageHeaders;
  1025. var Counter_1    : Integer;
  1026.     TheEMMRecord : PEMailMessageRecord;
  1027.     TempString   : String;
  1028. begin
  1029.   { Clear target list box }
  1030.   ListBox2.Clear;
  1031.   for Counter_1 := 0 to TheMBMessagesList.Count - 1 do
  1032.   begin
  1033.     TheEMMRecord :=
  1034.      PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  1035.     TempString := '    [' + IntToStr( Counter_1 + 1 ) + '] ' +
  1036.      TheEMMRecord^.MRMessageSubject;
  1037.     if TheEMMRecord^.MRRead then TempString[ 2 ] := 'R';
  1038.     if TheEMMRecord^.MRSent then TempString[ 2 ] := 'S';
  1039.     if TheEMMRecord^.MRMessageSender = 'DELETE ME' then TempString[ 3 ] := 'T';
  1040.     ListBox2.Items.Add( TempString );
  1041.   end;
  1042. end;
  1043.  
  1044. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  1045. { and calls another procedure to populate LB2 with any available   }
  1046. { articles for the newsgroup.                                      }
  1047. procedure TCCINetCCForm.SetupEMailListboxes;
  1048. var Counter_1   : Integer;
  1049.     TempString  : String;
  1050.     TheMBRecord : PEMailMailboxRecord;
  1051. begin
  1052.   ListBox1.Clear;
  1053.   ListBox1.Tag := 6;
  1054.   ListBox2.Tag := 6;
  1055.   Label4.Caption := 'Mailboxes';
  1056.   Label5.Caption := 'Messages';
  1057.   if TheEMailMailboxList.Count = 0 then
  1058.   begin
  1059.     ListBox2.Clear;
  1060.     exit;
  1061.   end;
  1062.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1063.   begin
  1064.     TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ Counter_1 ] );
  1065.     TempString := TheMBRecord^.MBName;
  1066.     if TheMBRecord^.MBUnSentTotal > 0 then TempString := TempString + ' {' +
  1067.      IntToStr( TheMBRecord^.MBUnSentTotal ) + ' Queued}' else
  1068.      if TheMBRecord^.MBUnReadTotal > 0 then TempString := TempString +
  1069.        ' {' + IntToStr( TheMBRecord^.MBUnReadTotal ) + ' New}';
  1070.     TempString := TempString + '{' + IntToStr( TheMBRecord^.MBTotal ) + ' Stored}';
  1071.     ListBox1.Items.Add( TempString );
  1072.   end;
  1073.   TheMBRecord := PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] );
  1074.   TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  1075.   PopulateLB2WithMessageHeaders;
  1076.   Label1.Caption := 'MailBox:';
  1077.   Button1.Caption := 'New Mail';
  1078. end;
  1079.  
  1080. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1081. procedure TCCINetCCForm.SetupEMailServersInfoDisplay;
  1082. var Counter_1  : Integer;            { Loop counter        }
  1083. begin
  1084.   { Set tag for POP3SMTP stuff }
  1085.   CCICInfoDlg.Tag := 6; { EMail Tag -- servers }
  1086.   { set up caption of main label }
  1087.   CCICInfoDlg.Label2.Caption := 'EMail Server Sites';
  1088.   { hide outline panel }
  1089.   CCICInfoDlg.Panel6.Top := 200;
  1090.   CCICInfoDlg.panel6.Height := 144;
  1091.   CCICInfoDlg.Panel6.Visible := false;
  1092.   CCICInfoDlg.Panel5.Visible := true;
  1093.   CCICInfoDlg.Panel8.Visible := true;
  1094.   CCICInfoDlg.Panel9.Visible := true;
  1095.   { clear the list box }
  1096.   CCICInfoDlg.ListBox1.Visible := false;
  1097.   CCICInfoDlg.ListBox2.Clear;
  1098.   CCINetCCForm.ComboBox1.Clear;
  1099.   { add profile strings to the list box }
  1100.   for Counter_1 := 0 to TheEMailServerList.Count - 1 do
  1101.   begin
  1102.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1103.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1104.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  1105.      TheEMailServerList.Items[ Counter_1 ] )^.CProfile );
  1106.   end;
  1107.   { Set up caption of special button }
  1108.   CCICInfoDlg.Button1.Visible := false;
  1109.   { Start with top record }
  1110.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1111.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  1112.   { put in data from top record and reset captions }
  1113.   with PConnectionsRecord( TheEMailServerList.Items[ 0 ] )^ do
  1114.   begin
  1115.     with CCICInfoDlg do
  1116.     begin
  1117.       Edit1.Text := CProfile;
  1118.       Panel2.Caption := '            Name:';
  1119.       Edit2.Text := CIPAddress;
  1120.       Panel3.Caption := '     IP Address:';
  1121.       Edit3.Text := CUserName;
  1122.       Panel5.Caption := '    User Name:';
  1123.       CurrentEMRealPWString := CPassword;
  1124.       case EMPasswordControlVector of
  1125.         1 : Edit4.Text := CPassword;
  1126.         2 : Edit4.Text := '**********';
  1127.       end;
  1128.       Panel8.Caption := '      Password:';
  1129.       Edit5.Text := CStartDir;
  1130.       Panel9.Caption := '    EMail Address:';
  1131.     end;
  1132.   end;
  1133. end;
  1134.  
  1135. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1136. procedure TCCINetCCForm.SetupEMailMailboxInfoDisplay;
  1137. var Counter_1      : Integer;
  1138.     TheWorkingList : TList;
  1139. begin
  1140.   { Set tag for POP3SMTP stuff }
  1141.   CCICInfoDlg.Tag := 7; { EMail Tag -- mailboxes }
  1142.   { set up caption of main label }
  1143.   CCICInfoDlg.Label2.Caption := 'Mailboxes';
  1144.   { hide outline panel }
  1145.   CCICInfoDlg.Panel6.Visible := true;
  1146.   CCICInfoDlg.Panel6.Top := 40;
  1147.   CCICInfoDlg.Panel6.Height := 304;
  1148.   CCICInfoDlg.Label1.Caption := 'Saved Messages';
  1149.   CCICInfoDlg.Panel3.Visible := false;
  1150.   CCICInfoDlg.Panel5.Visible := false;
  1151.   CCICInfoDlg.Panel8.Visible := false;
  1152.   CCICInfoDlg.Panel9.Visible := false;
  1153.   { clear the list box }
  1154.   CCICInfoDlg.ListBox1.Visible := true;
  1155.   CCICInfoDlg.ListBox1.MultiSelect := true;
  1156.   CCICInfoDlg.ListBox1.ExtendedSelect := true;
  1157.   CCICInfoDlg.ListBox2.Clear;
  1158.   CCICInfoDlg.ListBox1.Clear;
  1159.   { add profile strings to the list box }
  1160.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  1161.   begin
  1162.     CCICInfoDlg.ListBox2.Items.Add( PEMailMailboxRecord(
  1163.      TheEMailMailboxList.Items[ Counter_1 ] )^.MBName );
  1164.   end;
  1165.   { Set up caption of special button }
  1166.   CCICInfoDlg.Button1.Visible := true;
  1167.   CCICInfoDlg.Button1.Caption := 'XFer on Click';
  1168.   { Start with top record }
  1169.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1170.   { put in data from top record and reset captions }
  1171.   with PEMailMailboxRecord( TheEMailMailboxList.Items[ 0 ] )^ do
  1172.   begin
  1173.     with CCICInfoDlg do
  1174.     begin
  1175.       Edit1.Text := MBName;
  1176.       Panel2.Caption := 'MB Name:';
  1177.       TheWorkingList := TList( MBLTag );
  1178.       if TheWorkingList.Count > 0 then
  1179.       begin
  1180.         ListBox1.Clear;
  1181.         for Counter_1 := 0 to TheWorkingList.Count - 1 do
  1182.         begin
  1183.           ListBox1.Items.Add( PEMailMessageRecord(
  1184.            TheWorkingList.Items[ Counter_1 ] )^.MRMessageSubject );
  1185.         end;
  1186.         Listbox1.ItemIndex := 0;
  1187.       end;
  1188.     end;
  1189.   end;
  1190. end;
  1191.  
  1192. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  1193. procedure TCCINetCCForm.SetupEMailCorrespondentsInfoDisplay;
  1194. var Counter_1  : Integer;            { Loop counter        }
  1195. begin
  1196.   { Set tag for POP3SMTP stuff }
  1197.   CCICInfoDlg.Tag := 8; { EMail Tag -- correspondents }
  1198.   { set up caption of main label }
  1199.   CCICInfoDlg.Label2.Caption := 'Correspondents';
  1200.   { hide outline panel }
  1201.   CCICInfoDlg.Panel3.Visible := true;
  1202.   CCICInfoDlg.Panel6.Visible := false;
  1203.   CCICInfoDlg.Panel5.Visible := false;
  1204.   CCICInfoDlg.Panel8.Visible := false;
  1205.   CCICInfoDlg.Panel9.Visible := false;
  1206.   CCICInfoDlg.ListBox1.Visible := false;
  1207.   { clear the list box }
  1208.   CCICInfoDlg.ListBox2.Clear;
  1209.   { add profile strings to the list box }
  1210.   for Counter_1 := 0 to TheCorrespondentsList.Count - 1 do
  1211.   begin
  1212.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  1213.      TheCorrespondentsList.Items[ Counter_1 ] )^.CProfile );
  1214.   end;
  1215.   { Set up caption of special button }
  1216.   CCICInfoDlg.Button1.Visible := false;
  1217.   { Start with top record }
  1218.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  1219.   { put in data from top record and reset captions }
  1220.   with PConnectionsRecord( TheCorrespondentsList.Items[ 0 ] )^ do
  1221.   begin
  1222.     with CCICInfoDlg do
  1223.     begin
  1224.       Edit1.Text := CProfile;
  1225.       Panel2.Caption := '            Name:';
  1226.       Edit2.Text := CIPAddress;
  1227.       Panel3.Caption := 'EMail Address:';
  1228.     end;
  1229.   end;
  1230. end;
  1231.  
  1232. procedure TCCINetCCForm.EnablePOP3SMTPMenus;
  1233. begin
  1234.   Button1.Caption := 'New Mail';
  1235.   CheckMail1.Enabled := true;
  1236.   CreateNewMessage1.Enabled := true;
  1237.   ReplyToCurrentMessage1.Enabled := true;
  1238.   SendCurrentMessage1.Enabled := true;
  1239.   SendQueue1.Enabled := true;
  1240.   MailServers1.Enabled := true;
  1241.   MailBoxes1.Enabled := true;
  1242.   Correspondents1.Enabled := true;
  1243.   TrashMarkedMessages1.Enabled := true;
  1244.   EmptyTrash1.Enabled := true;
  1245. end;
  1246.  
  1247. procedure TCCINetCCForm.DisablePOP3SMTPMenus;
  1248. begin
  1249.   CheckMail1.Enabled := False;
  1250.   CreateNewMessage1.Enabled := False;
  1251.   ReplyToCurrentMessage1.Enabled := False;
  1252.   SendCurrentMessage1.Enabled := False;
  1253.   SendQueue1.Enabled := False;
  1254.   MailServers1.Enabled := False;
  1255.   MailBoxes1.Enabled := False;
  1256.   Correspondents1.Enabled := False;
  1257.   TrashMarkedMessages1.Enabled := False;
  1258.   EmptyTrash1.Enabled := False;
  1259.   EMail1.Enabled := true;
  1260.   FTP1.Enabled := true;
  1261.   UseNetNws1.Enabled := true;
  1262.   IPAddress1.Enabled := true;
  1263.   EMail2.Enabled := false;
  1264. end;
  1265.  
  1266. { This is the FTP component constructor; it creates 2 sockets }
  1267. constructor TFTPComponent.Create( AOwner : TComponent );
  1268. begin
  1269.   { do inherited create }
  1270.   inherited Create( AOwner );
  1271.   { Create sockets, put in their parents, and error procs }
  1272.   Socket1 := TCCSocket.Create( Self );
  1273.   Socket1.Parent := Self;
  1274.   Socket1.OnErrorOccurred := FTPSocketsErrorOccurred;
  1275.   Socket2 := TCCSocket.Create( Self );
  1276.   Socket2.Parent := Self;
  1277.   Socket2.OnErrorOccurred := FTPSocketsErrorOccurred;
  1278.   { Set up booleans }
  1279.   Connection_Established := false;
  1280.   FTPCommandInProgress := false;
  1281. end;
  1282.  
  1283. { This is the FTP component destructor; it frees 2 sockets }
  1284. destructor TFTPComponent.Destroy;
  1285. begin
  1286.   { Free the sockets }
  1287.   Socket1.Free;
  1288.   Socket2.Free;
  1289.   { and call inherited }
  1290.   inherited Destroy;
  1291. end;
  1292.  
  1293. function TFTPComponent.GetShortPathname( TheString : String ) : String;
  1294. var HoldingString : String;
  1295. begin
  1296.   HoldingString := Copy( TheString , 1 , 3 );
  1297.   HoldingString := HoldingString + '..\' + ExtractFileName( TheString );
  1298.   Result := HoldingString;
  1299. end;
  1300.  
  1301. function TFTPComponent.StripBrackets( TheString : String ) : String;
  1302. var HoldingString : String;
  1303.     HoldingPosition : Integer;
  1304. begin
  1305.   HoldingPosition := Pos( '[' , TheString );
  1306.   if HoldingPosition = 0 then
  1307.   begin
  1308.     Result := TheString;
  1309.     exit;
  1310.   end
  1311.   else
  1312.   begin
  1313.     HoldingString := Copy( TheString , HoldingPosition + 1 , 255 );
  1314.     HoldingPosition := Pos( ']' , HoldingString );
  1315.     if HoldingPosition = 0 then
  1316.     begin
  1317.       Result := HoldingString;
  1318.       exit;
  1319.     end
  1320.     else
  1321.     begin
  1322.       HoldingString := Copy( HoldingString , 1 , HoldingPosition - 1 );
  1323.       Result := HoldingString;
  1324.       exit;
  1325.     end;
  1326.   end;
  1327. end;
  1328.  
  1329. { This function takes a UNIX filespec and turns it into a Win16 filename }
  1330. function TFTPComponent.GetWin16FileName( InputName : String ) : String;
  1331. var WorkingString ,
  1332.     HoldingString   : String; { Holding string }
  1333. begin
  1334.   WorkingString := ExtractFileExt( InputName );
  1335.   if WorkingString = '' then
  1336.   begin
  1337.     if Length( InputName ) > 8 then
  1338.      WorkingString := Copy( InputName , 1 , 8 ) else
  1339.       WorkingString := InputName;
  1340.   end
  1341.   else
  1342.   begin
  1343.     if Length( WorkingString ) > 4 then
  1344.      WorkingString := Copy( WorkingString , 1 , 4 );
  1345.     HoldingString :=
  1346.      Copy( InputName , 1 , Pos( WorkingString , InputName ) - 1 );
  1347.     if Length( HoldingString ) > 8 then
  1348.      HoldingString := Copy( HoldingString , 1 , 8 );
  1349.     if HoldingString = '' then
  1350.     begin
  1351.       { Dot file }
  1352.       HoldingString := Copy( InputName , 2 , 255 ) + '.TXT';
  1353.       WorkingString := HoldingString;
  1354.     end
  1355.     else WorkingString := HoldingString + WorkingString;
  1356.   end;
  1357.   Result := WorkingString;
  1358. end;
  1359.  
  1360. { This sends a local file in binary mode to the remote server }
  1361. procedure TFTPComponent.SendBinaryLocalFile( LocalName : String );
  1362. var TheReturnString : String;  { Internal string holder }
  1363.     TheResult       : Integer; { Internal int holder    }
  1364.     Through         : Boolean;
  1365.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1366.     OutputFileHandle : Integer;
  1367.     TotalBytesSent ,
  1368.     BytesRead ,
  1369.     FileToSendSize    : Longint;
  1370.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1371. begin
  1372.   LocalName := ExpandFileName( LocalName );
  1373.   StrPCopy( FileNamePChar , LocalName );
  1374.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1375.   if OutputFileHandle = -1 then
  1376.   begin
  1377.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1378.      mtError , [mbOK] , 0 );
  1379.     exit;
  1380.   end;
  1381.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1382.   _llseek( OutputFileHandle , 0 , 0 );
  1383.   TheReturnString :=
  1384.    DoCStyleFormat( 'TYPE I' ,
  1385.     [ nil ] );
  1386.   { Put result in progress and status line }
  1387.   AddProgressText( TheReturnString );
  1388.   ShowProgressText( TheReturnString );
  1389.   { Send Password sequence }
  1390.   TheResult := PerformFTPCommand( 'TYPE I',
  1391.                                   [ nil ] );
  1392.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1393.   begin
  1394.     FTPCommandInProgress := false;
  1395.     exit;
  1396.   end;
  1397.   repeat
  1398.     TheResult := GetFTPServerResponse( TheReturnString );
  1399.     { Put result in progress and status line }
  1400.     AddProgressText( TheReturnString );
  1401.     ShowProgressText( TheReturnString );
  1402.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1403.   FTPCommandInProgress := false;
  1404.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1405.   begin
  1406.     { Do clever C formatting trick }
  1407.     TheReturnString :=
  1408.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1409.       [ nil ] );
  1410.     { Put result in progress and status line }
  1411.     AddProgressText( TheReturnString );
  1412.     ShowProgressErrorText( TheReturnString );
  1413.     { leave }
  1414.     exit;
  1415.   end
  1416.   else
  1417.   begin
  1418.     { Set up socket 2 for listening }
  1419.     Socket2.AsynchMode := False;
  1420.     Socket2.NonAsynchTimeoutValue := 60;
  1421.     { do a listen and send command to server that this is receipt socket }
  1422.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1423.     begin
  1424.       Socket2.CCSockCancelListen;
  1425.       exit;
  1426.     end;
  1427.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1428.     TheReturnString :=
  1429.      DoCStyleFormat( 'STOR %s' ,
  1430.       [ ExtractFileName( LocalName ) ] );
  1431.     { Put result in progress and status line }
  1432.     AddProgressText( TheReturnString );
  1433.     ShowProgressText( TheReturnString );
  1434.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName ) ] );
  1435.     GetFTPServerResponse( TheReturnString );
  1436.     AddProgressText( TheReturnString );
  1437.     ShowProgressText( TheReturnString );
  1438.     Socket1.NonAsynchTimeoutValue := 30;
  1439.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1440.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1441.     begin
  1442.       TheReturnString :=
  1443.        DoCStyleFormat( 'Could not create remote file!' ,
  1444.         [ nil ] );
  1445.       { Put result in progress and status line }
  1446.       AddProgressText( TheReturnString );
  1447.       ShowProgressErrorText( TheReturnString );
  1448.       Socket2.CCSockCancelListen;
  1449.       exit;
  1450.     end;
  1451.     Socket2.CCSockAccept;
  1452.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1453.     begin
  1454.       TheReturnString :=
  1455.        DoCStyleFormat( 'Could not establish send socket!' ,
  1456.         [ nil ] );
  1457.       { Put result in progress and status line }
  1458.       AddProgressText( TheReturnString );
  1459.       ShowProgressErrorText( TheReturnString );
  1460.       exit;
  1461.     end;
  1462.     Through := false;
  1463.     TotalBytesSent := 0;
  1464.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1465.     repeat
  1466.       if BytesRead = 0 then Through := true;
  1467.       if BytesRead > 0 then
  1468.       begin
  1469.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1470.         Socket2.StringData := TheReturnString;
  1471.         TotalBytesSent := TotalBytesSent + BytesRead;
  1472.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1473.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1474.         if BytesRead = -1 then
  1475.         begin
  1476.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1477.           GlobalAbortedFlag := True;
  1478.         end;
  1479.       end;
  1480.       if GlobalAbortedFlag then
  1481.       begin
  1482.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1483.         repeat
  1484.           TheResult := GetFTPServerResponse( TheReturnString );
  1485.           { Put result in progress and status line }
  1486.           AddProgressText( TheReturnString );
  1487.           ShowProgressText( TheReturnString );
  1488.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1489.         exit;
  1490.       end;
  1491.     until Through;
  1492.     FTPCommandInProgress := false;
  1493.     { cancel listening on second socket and close it }
  1494.     Socket2.CCSockCancelListen;
  1495.     Socket2.CCSockClose;
  1496.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1497.     AddProgressText( TheReturnString );
  1498.     ShowProgressText( TheReturnString );
  1499.     FTPCommandInProgress := false;
  1500.     PerformFTPCommand( 'TYPE A',
  1501.                                     [ nil ] );
  1502.     Through := false;
  1503.     repeat
  1504.       GetFTPServerResponse( TheReturnString );
  1505.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1506.        Through := true;
  1507.       { Put result in progress and status line }
  1508.       AddProgressText( TheReturnString );
  1509.       ShowProgressText( TheReturnString );
  1510.     until (( GlobalAbortedFlag ) or Through );
  1511.   end;
  1512.   _lclose( OutputFileHandle );
  1513.   FTPCommandInProgress := false;
  1514. end;
  1515.  
  1516. { This sends a local file in ascii mode to remote server }
  1517. procedure TFTPComponent.SendASCIILocalFile( LocalName : String );
  1518. var TheReturnString : String;  { Internal string holder }
  1519.     TheResult       : Integer; { Internal int holder    }
  1520.     Through         : Boolean;
  1521.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1522.     OutputFileHandle : Integer;
  1523.     TotalBytesSent ,
  1524.     BytesRead ,
  1525.     FileToSendSize    : Longint;
  1526.     CopyBuffer       : array[ 0 .. 255 ] of char absolute TheReturnString;
  1527. begin
  1528.   LocalName := ExpandFileName( LocalName );
  1529.   StrPCopy( FileNamePChar , LocalName );
  1530.   OutputFileHandle := _lopen( FileNamePChar , 0 );
  1531.   if OutputFileHandle = -1 then
  1532.   begin
  1533.     MessageDlg( 'Cannot Open local file ' + LocalName ,
  1534.      mtError , [mbOK] , 0 );
  1535.     exit;
  1536.   end;
  1537.   FileToSendSize := _llseek( OutputFileHandle , 0 , 2 );
  1538.   _llseek( OutputFileHandle , 0 , 0 );
  1539.   TheReturnString :=
  1540.    DoCStyleFormat( 'TYPE A' ,
  1541.     [ nil ] );
  1542.   { Put result in progress and status line }
  1543.   AddProgressText( TheReturnString );
  1544.   ShowProgressText( TheReturnString );
  1545.   { Send Password sequence }
  1546.   TheResult := PerformFTPCommand( 'TYPE A',
  1547.                                   [ nil ] );
  1548.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1549.   begin
  1550.     FTPCommandInProgress := false;
  1551.     exit;
  1552.   end;
  1553.   repeat
  1554.     TheResult := GetFTPServerResponse( TheReturnString );
  1555.     { Put result in progress and status line }
  1556.     AddProgressText( TheReturnString );
  1557.     ShowProgressText( TheReturnString );
  1558.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1559.   FTPCommandInProgress := false;
  1560.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1561.   begin
  1562.     { Do clever C formatting trick }
  1563.     TheReturnString :=
  1564.      DoCStyleFormat( 'FTP File Send Failed!' ,
  1565.       [ nil ] );
  1566.     { Put result in progress and status line }
  1567.     AddProgressText( TheReturnString );
  1568.     ShowProgressErrorText( TheReturnString );
  1569.     { leave }
  1570.     exit;
  1571.   end
  1572.   else
  1573.   begin
  1574.     { Set up socket 2 for listening }
  1575.     Socket2.AsynchMode := False;
  1576.     Socket2.NonAsynchTimeoutValue := 60;
  1577.     { do a listen and send command to server that this is receipt socket }
  1578.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1579.     begin
  1580.       Socket2.CCSockCancelListen;
  1581.       exit;
  1582.     end;
  1583.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1584.     TheReturnString :=
  1585.      DoCStyleFormat( 'STOR %s' ,
  1586.       [ ExtractFileName( LocalName ) ] );
  1587.     { Put result in progress and status line }
  1588.     AddProgressText( TheReturnString );
  1589.     ShowProgressText( TheReturnString );
  1590.     TheResult := PerformFTPCommand( 'STOR %s' , [ ExtractFileName( LocalName )]);
  1591.     GetFTPServerResponse( TheReturnString );
  1592.     AddProgressText( TheReturnString );
  1593.     ShowProgressText( TheReturnString );
  1594.     Socket1.NonAsynchTimeoutValue := 30;
  1595.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1596.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1597.     begin
  1598.       TheReturnString :=
  1599.        DoCStyleFormat( 'Could not create remote file!' ,
  1600.         [ nil ] );
  1601.       { Put result in progress and status line }
  1602.       AddProgressText( TheReturnString );
  1603.       ShowProgressErrorText( TheReturnString );
  1604.       Socket2.CCSockCancelListen;
  1605.       exit;
  1606.     end;
  1607.     Socket2.CCSockAccept;
  1608.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1609.     begin
  1610.       TheReturnString :=
  1611.        DoCStyleFormat( 'Could not establish send socket!' ,
  1612.         [ nil ] );
  1613.       { Put result in progress and status line }
  1614.       AddProgressText( TheReturnString );
  1615.       ShowProgressErrorText( TheReturnString );
  1616.       exit;
  1617.     end;
  1618.     Through := false;
  1619.     TotalBytesSent := 0;
  1620.     BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1621.     repeat
  1622.       if BytesRead = 0 then Through := true;
  1623.       if BytesRead > 0 then
  1624.       begin
  1625.         CopyBuffer[ 0 ] := Chr( BytesRead );
  1626.         Socket2.StringData := TheReturnString;
  1627.         TotalBytesSent := TotalBytesSent + BytesRead;
  1628.         UpdateGauge( TotalBytesSent , FileToSendSize );
  1629.         BytesRead := _lread( OutputFileHandle , @CopyBuffer[ 1 ] , 255 );
  1630.         if BytesRead = -1 then
  1631.         begin
  1632.           MessageDlg( 'File Read Error on ' + LocalName , mtError , [mbOK] , 0 );
  1633.           GlobalAbortedFlag := True;
  1634.         end;
  1635.       end;
  1636.       if GlobalAbortedFlag then
  1637.       begin
  1638.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1639.         repeat
  1640.           TheResult := GetFTPServerResponse( TheReturnString );
  1641.           { Put result in progress and status line }
  1642.           AddProgressText( TheReturnString );
  1643.           ShowProgressText( TheReturnString );
  1644.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1645.         exit;
  1646.       end;
  1647.     until Through;
  1648.     { cancel listening on second socket and close it }
  1649.     Socket2.CCSockCancelListen;
  1650.     Socket2.CCSockClose;
  1651.     TheReturnString := 'Transfer Succeeded' + #13#10;
  1652.     AddProgressText( TheReturnString );
  1653.     ShowProgressText( TheReturnString );
  1654.     FTPCommandInProgress := false;
  1655.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1656.     Through := false;
  1657.     repeat
  1658.       GetFTPServerResponse( TheReturnString );
  1659.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1660.        Through := true;
  1661.       { Put result in progress and status line }
  1662.       AddProgressText( TheReturnString );
  1663.       ShowProgressText( TheReturnString );
  1664.     until (( GlobalAbortedFlag ) or Through );
  1665.   end;
  1666.   _lclose( OutputFileHandle );
  1667.   FTPCommandInProgress := false;
  1668. end;
  1669.  
  1670. { This function strips out the FTP response for bytes to send }
  1671. function TFTPComponent.GetTotalBytesToReceive( TheString : String ) : Longint;
  1672. var
  1673.   LeftPosition ,
  1674.   RightPosition  : integer;
  1675.   TempString     : string;
  1676. begin
  1677.   LeftPosition := Pos( '(' , TheString );
  1678.   TempString := Copy( TheString ,
  1679.                       LeftPosition + 1 , 255 );
  1680.   RightPosition := Pos( ' ' , TempString );
  1681.   if (( LeftPosition = 0 ) or ( RightPosition = 0 )) then
  1682.   begin
  1683.     Result := 0;
  1684.     exit;
  1685.   end;
  1686.   if RightPosition <> 0 then
  1687.     TempString := Copy( TempString , 1 , RightPosition - 1  );
  1688.   try
  1689.     Result := StrToInt( TempString );
  1690.   except
  1691.     on EConvertError do Result := 0;
  1692.   end;
  1693. end;
  1694.  
  1695. procedure TFTPComponent.UpdateGauge( BytesFinished , TotalToHandle : longint );
  1696. begin
  1697.   CCInetCCForm.UpdateGauge( BytesFinished , TotalToHandle );
  1698. end;
  1699.  
  1700. { This sends FTP progress text to the Inet form }
  1701. procedure TFTPComponent.AddProgressText( WhatText : String );
  1702. begin
  1703.   CCInetCCForm.AddProgressText( WhatText );
  1704. end;
  1705.  
  1706. { This sends FTP progress text to the Inet form }
  1707. procedure TFTPComponent.ShowProgressText( WhatText : String );
  1708. begin
  1709.   CCInetCCForm.ShowProgressText( WhatText );
  1710. end;
  1711.  
  1712. { This procedure receives a binary remote file }
  1713. procedure TFTPComponent.ReceiveASCIIRemoteFileToMemo( RemoteName : String );
  1714. var TheReturnString : String;  { Internal string holder }
  1715.     TheResult       : Integer; { Internal int holder    }
  1716.     Through         : Boolean;
  1717.     TotalBytesSent ,
  1718.     FileToGetSize    : Longint;
  1719. begin
  1720.   TheReturnString :=
  1721.    DoCStyleFormat( 'TYPE A' ,
  1722.     [ nil ] );
  1723.   { Put result in progress and status line }
  1724.   AddProgressText( TheReturnString );
  1725.   ShowProgressText( TheReturnString );
  1726.   { Send Password sequence }
  1727.   FTPCommandInProgress := false;
  1728.   TheResult := PerformFTPCommand( 'TYPE A',
  1729.                                   [ nil ] );
  1730.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1731.   begin
  1732.     FTPCommandInProgress := false;
  1733.     exit;
  1734.   end;
  1735.   repeat
  1736.     TheResult := GetFTPServerResponse( TheReturnString );
  1737.     { Put result in progress and status line }
  1738.     AddProgressText( TheReturnString );
  1739.     ShowProgressText( TheReturnString );
  1740.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1741.   FTPCommandInProgress := false;
  1742.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1743.   begin
  1744.     { Do clever C formatting trick }
  1745.     TheReturnString :=
  1746.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1747.       [ nil ] );
  1748.     { Put result in progress and status line }
  1749.     AddProgressText( TheReturnString );
  1750.     ShowProgressErrorText( TheReturnString );
  1751.     { leave }
  1752.     exit;
  1753.   end
  1754.   else
  1755.   begin
  1756.     { Set up socket 2 for listening }
  1757.     Socket2.AsynchMode := False;
  1758.     Socket2.NonAsynchTimeoutValue := 60;
  1759.     { do a listen and send command to server that this is receipt socket }
  1760.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1761.     begin
  1762.       Socket2.CCSockCancelListen;
  1763.       exit;
  1764.     end;
  1765.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1766.     TheReturnString :=
  1767.      DoCStyleFormat( 'RETR %s' ,
  1768.       [ RemoteName ] );
  1769.     { Put result in progress and status line }
  1770.     AddProgressText( TheReturnString );
  1771.     ShowProgressText( TheReturnString );
  1772.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1773.     GetFTPServerResponse( TheReturnString );
  1774.     AddProgressText( TheReturnString );
  1775.     ShowProgressText( TheReturnString );
  1776.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1777.     Socket1.NonAsynchTimeoutValue := 30;
  1778.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1779.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1780.     begin
  1781.       TheReturnString :=
  1782.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1783.         [ nil ] );
  1784.       { Put result in progress and status line }
  1785.       AddProgressText( TheReturnString );
  1786.       ShowProgressErrorText( TheReturnString );
  1787.       Socket2.CCSockCancelListen;
  1788.       exit;
  1789.     end;
  1790.     Socket2.CCSockAccept;
  1791.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1792.     begin
  1793.       TheReturnString :=
  1794.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1795.         [ nil ] );
  1796.       { Put result in progress and status line }
  1797.       AddProgressText( TheReturnString );
  1798.       ShowProgressErrorText( TheReturnString );
  1799.       exit;
  1800.     end;
  1801.     Through := false;
  1802.     TotalBytesSent := 0;
  1803.     repeat
  1804.       TheReturnString := Socket2.StringData;
  1805.       if Length( TheReturnString ) = 0 then Through := true;
  1806.       if Length( TheReturnString ) > 0 then
  1807.       begin
  1808.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1809.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1810.         { Put result in progress and status line }
  1811.         AddProgressText( TheReturnString );
  1812.         ShowProgressText( TheReturnString );
  1813.       end;
  1814.       if GlobalAbortedFlag then
  1815.       begin
  1816.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1817.         repeat
  1818.           TheResult := GetFTPServerResponse( TheReturnString );
  1819.           { Put result in progress and status line }
  1820.           AddProgressText( TheReturnString );
  1821.           ShowProgressText( TheReturnString );
  1822.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1823.         exit;
  1824.       end;
  1825.     until Through;
  1826.     { cancel listening on second socket and close it }
  1827.     Socket2.CCSockCancelListen;
  1828.     Socket2.CCSockClose;
  1829.     FTPCommandInProgress := false;
  1830.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1831.     Through := false;
  1832.     repeat
  1833.       GetFTPServerResponse( TheReturnString );
  1834.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1835.        Through := true;
  1836.       { Put result in progress and status line }
  1837.       AddProgressText( TheReturnString );
  1838.       ShowProgressText( TheReturnString );
  1839.     until (( GlobalAbortedFlag ) or Through );
  1840.   end;
  1841.   FTPCommandInProgress := false;
  1842. end;
  1843.  
  1844. { This procedure receives a binary remote file }
  1845. procedure TFTPComponent.ReceiveASCIIRemoteFile( RemoteName , LocalName : String );
  1846. var TheReturnString : String;  { Internal string holder }
  1847.     TheResult       : Integer; { Internal int holder    }
  1848.     Through         : Boolean;
  1849.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1850.     OutputFileHandle : Integer;
  1851.     TotalBytesSent ,
  1852.     FileToGetSize    : Longint;
  1853.     CopyBuffer       : array[ 0 .. 255 ] of char;
  1854. begin
  1855.   LocalName := ExpandFileName( LocalName );
  1856.   StrPCopy( FileNamePChar , LocalName );
  1857.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  1858.   if OutputFileHandle = -1 then
  1859.   begin
  1860.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  1861.      mtError , [mbOK] , 0 );
  1862.     exit;
  1863.   end;
  1864.   TheReturnString :=
  1865.    DoCStyleFormat( 'TYPE A' ,
  1866.     [ nil ] );
  1867.   { Put result in progress and status line }
  1868.   AddProgressText( TheReturnString );
  1869.   ShowProgressText( TheReturnString );
  1870.   { Send Password sequence }
  1871.   TheResult := PerformFTPCommand( 'TYPE A',
  1872.                                   [ nil ] );
  1873.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  1874.   begin
  1875.     FTPCommandInProgress := false;
  1876.     exit;
  1877.   end;
  1878.   repeat
  1879.     TheResult := GetFTPServerResponse( TheReturnString );
  1880.     { Put result in progress and status line }
  1881.     AddProgressText( TheReturnString );
  1882.     ShowProgressText( TheReturnString );
  1883.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1884.   FTPCommandInProgress := false;
  1885.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  1886.   begin
  1887.     { Do clever C formatting trick }
  1888.     TheReturnString :=
  1889.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  1890.       [ nil ] );
  1891.     { Put result in progress and status line }
  1892.     AddProgressText( TheReturnString );
  1893.     ShowProgressErrorText( TheReturnString );
  1894.     { leave }
  1895.     exit;
  1896.   end
  1897.   else
  1898.   begin
  1899.     { Set up socket 2 for listening }
  1900.     Socket2.AsynchMode := False;
  1901.     Socket2.NonAsynchTimeoutValue := 60;
  1902.     { do a listen and send command to server that this is receipt socket }
  1903.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  1904.     begin
  1905.       Socket2.CCSockCancelListen;
  1906.       exit;
  1907.     end;
  1908.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  1909.     TheReturnString :=
  1910.      DoCStyleFormat( 'RETR %s' ,
  1911.       [ RemoteName ] );
  1912.     { Put result in progress and status line }
  1913.     AddProgressText( TheReturnString );
  1914.     ShowProgressText( TheReturnString );
  1915.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  1916.     GetFTPServerResponse( TheReturnString );
  1917.     AddProgressText( TheReturnString );
  1918.     ShowProgressText( TheReturnString );
  1919.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  1920.     Socket1.NonAsynchTimeoutValue := 30;
  1921.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  1922.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  1923.     begin
  1924.       TheReturnString :=
  1925.        DoCStyleFormat( 'Could not obtain remote file!' ,
  1926.         [ nil ] );
  1927.       { Put result in progress and status line }
  1928.       AddProgressText( TheReturnString );
  1929.       ShowProgressErrorText( TheReturnString );
  1930.       Socket2.CCSockCancelListen;
  1931.       exit;
  1932.     end;
  1933.     Socket2.CCSockAccept;
  1934.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  1935.     begin
  1936.       TheReturnString :=
  1937.        DoCStyleFormat( 'Could not establish receive socket!' ,
  1938.         [ nil ] );
  1939.       { Put result in progress and status line }
  1940.       AddProgressText( TheReturnString );
  1941.       ShowProgressErrorText( TheReturnString );
  1942.       exit;
  1943.     end;
  1944.     Through := false;
  1945.     TotalBytesSent := 0;
  1946.     repeat
  1947.       TheReturnString := Socket2.StringData;
  1948.       if Length( TheReturnString ) = 0 then Through := true;
  1949.       if Length( TheReturnString ) > 0 then
  1950.       begin
  1951.         StrPCopy( CopyBuffer , TheReturnString );
  1952.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  1953.         UpdateGauge( TotalBytesSent , FileToGetSize );
  1954.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  1955.          = -1 then
  1956.         begin
  1957.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  1958.           GlobalAbortedFlag := True;
  1959.         end;
  1960.       end;
  1961.       if GlobalAbortedFlag then
  1962.       begin
  1963.         Socket1.OutOfBand := 'ABOR'+#13#10;
  1964.         repeat
  1965.           TheResult := GetFTPServerResponse( TheReturnString );
  1966.           { Put result in progress and status line }
  1967.           AddProgressText( TheReturnString );
  1968.           ShowProgressText( TheReturnString );
  1969.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  1970.         exit;
  1971.       end;
  1972.     until Through;
  1973.     { cancel listening on second socket and close it }
  1974.     Socket2.CCSockCancelListen;
  1975.     Socket2.CCSockClose;
  1976.     FTPCommandInProgress := false;
  1977.     PerformFTPCommand( 'TYPE A', [ nil ] );
  1978.     Through := false;
  1979.     repeat
  1980.       GetFTPServerResponse( TheReturnString );
  1981.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  1982.        Through := true;
  1983.       { Put result in progress and status line }
  1984.       AddProgressText( TheReturnString );
  1985.       ShowProgressText( TheReturnString );
  1986.     until (( GlobalAbortedFlag ) or Through );
  1987.   end;
  1988.   _lclose( OutputFileHandle );
  1989.   FTPCommandInProgress := false;
  1990. end;
  1991.  
  1992. { This procedure receives a binary remote file }
  1993. procedure TFTPComponent.ReceiveBinaryRemoteFile( RemoteName , LocalName : String );
  1994. var TheReturnString : String;  { Internal string holder }
  1995.     TheResult       : Integer; { Internal int holder    }
  1996.     Through         : Boolean;
  1997.     FileNamePChar   : array[ 0 .. 255 ] of char;
  1998.     OutputFileHandle : Integer;
  1999.     TotalBytesSent ,
  2000.     FileToGetSize    : Longint;
  2001.     CopyBuffer       : array[ 0 .. 255 ] of char;
  2002. begin
  2003.   LocalName := ExpandFileName( LocalName );
  2004.   StrPCopy( FileNamePChar , LocalName );
  2005.   OutputFileHandle := _lcreat( FileNamePChar , 0 );
  2006.   if OutputFileHandle = -1 then
  2007.   begin
  2008.     MessageDlg( 'Cannot Create local file ' + LocalName ,
  2009.      mtError , [mbOK] , 0 );
  2010.     exit;
  2011.   end;
  2012.   TheReturnString :=
  2013.    DoCStyleFormat( 'TYPE I' ,
  2014.     [ nil ] );
  2015.   { Put result in progress and status line }
  2016.   AddProgressText( TheReturnString );
  2017.   ShowProgressText( TheReturnString );
  2018.   { Send Password sequence }
  2019.   TheResult := PerformFTPCommand( 'TYPE I',
  2020.                                   [ nil ] );
  2021.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2022.   begin
  2023.     FTPCommandInProgress := false;
  2024.     exit;
  2025.   end;
  2026.   repeat
  2027.     TheResult := GetFTPServerResponse( TheReturnString );
  2028.     { Put result in progress and status line }
  2029.     AddProgressText( TheReturnString );
  2030.     ShowProgressText( TheReturnString );
  2031.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2032.   FTPCommandInProgress := false;
  2033.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2034.   begin
  2035.     { Do clever C formatting trick }
  2036.     TheReturnString :=
  2037.      DoCStyleFormat( 'FTP File Receive Failed!' ,
  2038.       [ nil ] );
  2039.     { Put result in progress and status line }
  2040.     AddProgressText( TheReturnString );
  2041.     ShowProgressErrorText( TheReturnString );
  2042.     { leave }
  2043.     exit;
  2044.   end
  2045.   else
  2046.   begin
  2047.     { Set up socket 2 for listening }
  2048.     Socket2.AsynchMode := False;
  2049.     Socket2.NonAsynchTimeoutValue := 60;
  2050.     { do a listen and send command to server that this is receipt socket }
  2051.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2052.     begin
  2053.       Socket2.CCSockCancelListen;
  2054.       exit;
  2055.     end;
  2056.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2057.     TheReturnString :=
  2058.      DoCStyleFormat( 'RETR %s' ,
  2059.       [ RemoteName ] );
  2060.     { Put result in progress and status line }
  2061.     AddProgressText( TheReturnString );
  2062.     ShowProgressText( TheReturnString );
  2063.     TheResult := PerformFTPCommand( 'RETR %s' , [RemoteName] );
  2064.     GetFTPServerResponse( TheReturnString );
  2065.     AddProgressText( TheReturnString );
  2066.     ShowProgressText( TheReturnString );
  2067.     FileToGetSize := GetTotalBytesToReceive( TheReturnString );
  2068.     Socket1.NonAsynchTimeoutValue := 30;
  2069.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2070.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2071.     begin
  2072.       TheReturnString :=
  2073.        DoCStyleFormat( 'Could not obtain remote file!' ,
  2074.         [ nil ] );
  2075.       { Put result in progress and status line }
  2076.       AddProgressText( TheReturnString );
  2077.       ShowProgressErrorText( TheReturnString );
  2078.       Socket2.CCSockCancelListen;
  2079.       exit;
  2080.     end;
  2081.     Socket2.CCSockAccept;
  2082.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2083.     begin
  2084.       TheReturnString :=
  2085.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2086.         [ nil ] );
  2087.       { Put result in progress and status line }
  2088.       AddProgressText( TheReturnString );
  2089.       ShowProgressErrorText( TheReturnString );
  2090.       exit;
  2091.     end;
  2092.     Through := false;
  2093.     TotalBytesSent := 0;
  2094.     repeat
  2095.       TheReturnString := Socket2.StringData;
  2096.       if Length( TheReturnString ) = 0 then Through := true;
  2097.       if Length( TheReturnString ) > 0 then
  2098.       begin
  2099.         StrPCopy( CopyBuffer , TheReturnString );
  2100.         TotalBytesSent := TotalBytesSent + Length( TheReturnString );
  2101.         UpdateGauge( TotalBytesSent , FileToGetSize );
  2102.         if _lwrite( OutputFileHandle , CopyBuffer , Length( TheReturnString ))
  2103.          = -1 then
  2104.         begin
  2105.           MessageDlg( 'File Write Error on ' + LocalName , mtError , [mbOK] , 0 );
  2106.           GlobalAbortedFlag := True;
  2107.         end;
  2108.       end;
  2109.       if GlobalAbortedFlag then
  2110.       begin
  2111.         Socket1.OutOfBand := 'ABOR'+#13#10;
  2112.         repeat
  2113.           TheResult := GetFTPServerResponse( TheReturnString );
  2114.           { Put result in progress and status line }
  2115.           AddProgressText( TheReturnString );
  2116.           ShowProgressText( TheReturnString );
  2117.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2118.         exit;
  2119.       end;
  2120.     until Through;
  2121.     { cancel listening on second socket and close it }
  2122.     Socket2.CCSockCancelListen;
  2123.     Socket2.CCSockClose;
  2124.     FTPCommandInProgress := false;
  2125.     PerformFTPCommand( 'TYPE A', [ nil ] );
  2126.     Through := false;
  2127.     repeat
  2128.       GetFTPServerResponse( TheReturnString );
  2129.       if Pos( 'TYPE' , Uppercase( TheReturnString )) > 0 then
  2130.        Through := true;
  2131.       { Put result in progress and status line }
  2132.       AddProgressText( TheReturnString );
  2133.       ShowProgressText( TheReturnString );
  2134.     until (( GlobalAbortedFlag ) or Through );
  2135.   end;
  2136.   _lclose( OutputFileHandle );
  2137.   FTPCommandInProgress := false;
  2138. end;
  2139.  
  2140. { This sends FTP progress text to the Inet form }
  2141. procedure TFTPComponent.ShowProgressErrorText( WhatText : String );
  2142. begin
  2143.   CCInetCCForm.ShowProgressErrorText( WhatText );
  2144. end;
  2145.  
  2146. { This is a core function! It performs an FTP command and if no timeout }
  2147. { return a preliminary ok.                                              }
  2148. function TFTPComponent.PerformFTPCommand(
  2149.                  TheCommand        : string;
  2150.            const TheArguments      : array of const ) : Integer;
  2151. var TheBuffer : string; { Text buffer }
  2152. begin
  2153.   { If command in progress send back -1 error }
  2154.   if FTPCommandInProgress then
  2155.   begin
  2156.     Result := -1;
  2157.     exit;
  2158.   end;
  2159.   { Set status variable }
  2160.   FTPCommandInProgress := True;
  2161.   { Set global error code }
  2162.   GlobalErrorCode := 0;
  2163.   { Format output string }
  2164.   TheBuffer := Format( TheCommand , TheArguments );
  2165.   { Preset failure code }
  2166.   Result := TCPIP_STATUS_FATAL_ERROR;
  2167.   { If invalid socket or no connection abort }
  2168.   if ( Socket1.TheSocket = INVALID_SOCKET ) or not Connection_Established then
  2169.    exit;
  2170.   { Send the buffer plus EOL chars }
  2171.   Socket1.StringData := TheBuffer + #13#10;
  2172.   { if abort due to timeout or other error exit }
  2173.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2174.   { Otherwise return preliminary code }
  2175.   Result := TCPIP_STATUS_PRELIMINARY;
  2176. end;
  2177.  
  2178. { This function gets up to 255 chars of data plus a return code from FTP serv }
  2179. function TFTPComponent.GetFTPServerResponse(
  2180.           var ResponseString : String ) : integer;
  2181. var
  2182.   { Buffer string for response line }
  2183.   TheBuffer     : string;
  2184.   { Pointer to the response string }
  2185.   BufferPointer : array[0..255] of char absolute TheBuffer;
  2186.   { Character to check for response code }
  2187.   ResponseChar   : char;
  2188.   { Pointers into returned string }
  2189.   TheIndex ,
  2190.   TheLength     : integer;
  2191.   { Control variable }
  2192.   LeftoversInPan ,
  2193.   Finished      : Boolean;
  2194. begin
  2195.   { Preset fatal error }
  2196.   Result := TCPIP_STATUS_FATAL_ERROR;
  2197.   { Start loop control }
  2198.   LeftoversInPan := false;
  2199.   Finished := false;
  2200.   repeat
  2201.     { Do a peek }
  2202.     TheBuffer := Socket1.PeekData;
  2203.     { If timeout or other error exit }
  2204.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2205.     { Find end of line character }
  2206.     TheIndex := Pos( #10 , TheBuffer );
  2207.     if TheIndex = 0 then
  2208.     begin
  2209.       TheIndex := Pos( #13 , TheBuffer );
  2210.       if TheIndex = 0 then
  2211.       begin
  2212.         TheIndex := Pos( #0 , TheBuffer );
  2213.         if TheIndex = 0 then
  2214.         begin
  2215.           TheIndex := Length( TheBuffer );
  2216.           LeftoversInPan := True;
  2217.           LeftoverText := LeftoverText + TheBuffer;
  2218.           LeftoversOnTable := false;
  2219.         end;
  2220.       end;
  2221.     end;
  2222.     { If an end of line then process the line }
  2223.     if TheIndex > 0 then
  2224.     begin
  2225.       { Get length of string }
  2226.       TheLength := TheIndex;
  2227.       { Receive actual data }
  2228.       Socket1.CCSockReceive( Socket1.TheSocket   ,
  2229.                              @BufferPointer[ 1 ] ,
  2230.                              TheLength              );
  2231.       { Abort if timeout or error }
  2232.       if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then exit;
  2233.       { Put in the length byte }
  2234.       BufferPointer[ 0 ] := Chr( TheLength );
  2235.       if LeftOversOnTable then
  2236.       begin
  2237.         LeftOversOnTable := false;
  2238.         ResponseString := LeftoverText + TheBuffer;
  2239.         TheBuffer := ResponseString;
  2240.         LeftoverText := '';
  2241.       end;
  2242.       if LeftoversInPan then
  2243.       begin
  2244.         LeftoversInPan := false;
  2245.         LeftoversOnTable := true;
  2246.       end;
  2247.       { If not a continuation line }
  2248.       if TheBuffer[ 4 ] <> '-' then
  2249.       begin
  2250.         { Get first number character }
  2251.         ResponseChar := TheBuffer[ 1 ];
  2252.         { Get the value of the number from 1 to 5 }
  2253.         if (( ResponseChar >= '1' ) and ( ResponseChar <= '5' )) then
  2254.         begin
  2255.           Finished := true;
  2256.           Result := Ord( ResponseChar ) - 48;
  2257.         end;
  2258.       end
  2259.       else
  2260.       begin
  2261.         { otherwise return preliminary result }
  2262.         Finished := true;
  2263.         Result := TCPIP_STATUS_PRELIMINARY;
  2264.       end;
  2265.     end
  2266.     else
  2267.     begin
  2268.     end;
  2269.   until ( Finished and ( not LeftoversOnTable ));
  2270.   { Return buffer as response string }
  2271.   ResponseString := TheBuffer;
  2272. end;
  2273.  
  2274. { Boilerplate error routine }
  2275. procedure TFTPComponent.FTPSocketsErrorOccurred( Sender     : TObject;
  2276.                                                  ErrorCode  : Integer;
  2277.                                                  TheMessage : String   );
  2278. begin
  2279.   CCInetCCForm.SocketsErrorOccurred( Sender,ErrorCode,TheMessage );
  2280. end;
  2281.  
  2282. { This is the FTP components initial connection routine }
  2283. function TFTPComponent.EstablishConnection(
  2284.           PCRPointer : PConnectionsRecord ) : Boolean;
  2285. var TheReturnString : String;  { Internal string holder }
  2286.     TheResult       : Integer; { Internal int holder    }
  2287. begin
  2288.   { Set default FTP Port value }
  2289.   Socket1.PortName := '21';
  2290.   { Get the ip address from the record }
  2291.   Socket1.IPAddressName := PCRPointer^.CIPAddress;
  2292.   { Set blocking mode }
  2293.   Socket1.AsynchMode := False;
  2294.   { Clear condition variables }
  2295.   GlobalErrorCode := 0;
  2296.   GlobalAbortedFlag := false;
  2297.   { Actually attempt to connect }
  2298.   Socket1.CCSockConnect;
  2299.   { Check if connected }
  2300.   if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 ) or
  2301.       ( Socket1.TheSocket = INVALID_SOCKET )) then
  2302.   begin { Didn't connect; signal error and abort }
  2303.     { Do clever C formatting trick }
  2304.     TheReturnString :=
  2305.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2306.       [ PCRPointer^.CIPAddress ] );
  2307.     { Put result in progress and status line }
  2308.     AddProgressText( TheReturnString );
  2309.     ShowProgressErrorText( TheReturnString );
  2310.     { Signal error }
  2311.     Result := False;
  2312.     { leave }
  2313.     exit;
  2314.   end
  2315.   else
  2316.   begin
  2317.     Connection_Established := true;
  2318.     { Signal successful connection }
  2319.     TheReturnString := DoCStyleFormat(
  2320.       'Connected on Local port: %s with IP: %s',
  2321.       [ Socket1.GetSocketPort( Socket1.TheSocket ),
  2322.         Socket1.GetSocketIPAddress( Socket1.TheSocket )]);
  2323.     { Put result in progress and status line }
  2324.     CCINetCCForm.AddProgressText( TheReturnString );
  2325.     CCINetCCForm.ShowProgressText( TheReturnString );
  2326.     TheReturnString := DoCStyleFormat(
  2327.      'Connected to Remote port: %s with IP: %s',
  2328.       [ Socket1.GetSocketPeerPort( Socket1.TheSocket ),
  2329.         Socket1.GetSocketPeerIPAddress( Socket1.TheSocket )]);
  2330.     { Put result in progress and status line }
  2331.     CCINetCCForm.AddProgressText( TheReturnString );
  2332.     CCINetCCForm.ShowProgressText( TheReturnString );
  2333.     TheReturnString := DoCStyleFormat( 'Successfully connected to %s',
  2334.      [ Socket1.IPAddressName ]);
  2335.     { Put result in progress and status line }
  2336.     CCINetCCForm.AddProgressText( TheReturnString );
  2337.     CCINetCCForm.ShowProgressText( TheReturnString );
  2338.     repeat
  2339.       TheResult := GetFTPServerResponse( TheReturnString );
  2340.       { Put result in progress and status line }
  2341.       AddProgressText( TheReturnString );
  2342.       ShowProgressText( TheReturnString );
  2343.     until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2344.     if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2345.     begin
  2346.       { Do clever C formatting trick }
  2347.       TheReturnString :=
  2348.        DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2349.         [ PCRPointer^.CIPAddress ] );
  2350.       { Put result in progress and status line }
  2351.       AddProgressText( TheReturnString );
  2352.       ShowProgressErrorText( TheReturnString );
  2353.       { Signal error }
  2354.       Result := False;
  2355.       { leave }
  2356.       exit;
  2357.     end
  2358.     else Result := true; { Signal no problem }
  2359.   end;
  2360. end;
  2361.  
  2362. { This is the FTP components USER login routine }
  2363. function TFTPComponent.LoginUser(
  2364.           PCRPointer : PConnectionsRecord ) : Boolean;
  2365. var TheReturnString : String;  { Internal string holder }
  2366.     TheResult       : Integer; { Internal int holder    }
  2367. begin
  2368.   TheReturnString :=
  2369.    DoCStyleFormat( 'USER %s' ,
  2370.     [ PCRPointer^.CUserName ] );
  2371.   { Put result in progress and status line }
  2372.   AddProgressText( TheReturnString );
  2373.   ShowProgressText( TheReturnString );
  2374.   { Begin login sequence with user name }
  2375.   TheResult := PerformFTPCommand( 'USER %s',
  2376.                                   [ PCRPointer^.CUserName ] );
  2377.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2378.   begin
  2379.     FTPCommandInProgress := false;
  2380.     Result := false;
  2381.     exit;
  2382.   end;
  2383.   repeat
  2384.     TheResult := GetFTPServerResponse( TheReturnString );
  2385.     { Put result in progress and status line }
  2386.     AddProgressText( TheReturnString );
  2387.     ShowProgressText( TheReturnString );
  2388.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2389.   FTPCommandInProgress := false;
  2390.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_CONTINUING )) then
  2391.   begin
  2392.     { Do clever C formatting trick }
  2393.     TheReturnString :=
  2394.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2395.       [ PCRPointer^.CIPAddress ] );
  2396.     { Put result in progress and status line }
  2397.     AddProgressText( TheReturnString );
  2398.     ShowProgressErrorText( TheReturnString );
  2399.     { Signal error }
  2400.     Result := False;
  2401.     { leave }
  2402.     exit;
  2403.   end
  2404.   else Result := true; { Signal no problem }
  2405. end;
  2406.  
  2407. function TFTPComponent.DeleteRemoteDirectory( TheDir : String ) : Boolean;
  2408. var TheReturnString : String;  { Internal string holder }
  2409.     TheResult       : Integer; { Internal int holder    }
  2410. begin
  2411.   TheReturnString := DoCStyleFormat( 'RMD %s' ,
  2412.    [ TheDir ] );
  2413.   { Put result in progress and status line }
  2414.   AddProgressText( TheReturnString );
  2415.   ShowProgressText( TheReturnString );
  2416.   { Send Password sequence }
  2417.   TheResult := PerformFTPCommand( 'RMD %s',
  2418.                                   [ TheDir ] );
  2419.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2420.   begin
  2421.     Result := false;
  2422.     FTPCommandInProgress := false;
  2423.     exit;
  2424.   end;
  2425.   repeat
  2426.     TheResult := GetFTPServerResponse( TheReturnString );
  2427.     { Put result in progress and status line }
  2428.     AddProgressText( TheReturnString );
  2429.     ShowProgressText( TheReturnString );
  2430.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2431.   FTPCommandInProgress := false;
  2432.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2433.   begin
  2434.     { Do clever C formatting trick }
  2435.     TheReturnString :=
  2436.      DoCStyleFormat( 'Delete Directory %s Failed!' ,
  2437.       [ TheDir ] );
  2438.     { Put result in progress and status line }
  2439.     AddProgressText( TheReturnString );
  2440.     ShowProgressErrorText( TheReturnString );
  2441.     { Signal error }
  2442.     Result := False;
  2443.     { leave }
  2444.     exit;
  2445.   end
  2446.   else Result := true; { Signal no problem }
  2447. end;
  2448.  
  2449. function TFTPComponent.CreateRemoteDirectory( TheDir : String ) : Boolean;
  2450. var TheReturnString : String;  { Internal string holder }
  2451.     TheResult       : Integer; { Internal int holder    }
  2452. begin
  2453.   TheReturnString := DoCStyleFormat( 'MKD %s' ,
  2454.     [ TheDir ] );
  2455.   { Put result in progress and status line }
  2456.   AddProgressText( TheReturnString );
  2457.   ShowProgressText( TheReturnString );
  2458.   { Send Password sequence }
  2459.   TheResult := PerformFTPCommand( 'MKD %s',
  2460.                                   [ TheDir ] );
  2461.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2462.   begin
  2463.     Result := false;
  2464.     FTPCommandInProgress := false;
  2465.     exit;
  2466.   end;
  2467.   repeat
  2468.     TheResult := GetFTPServerResponse( TheReturnString );
  2469.     { Put result in progress and status line }
  2470.     AddProgressText( TheReturnString );
  2471.     ShowProgressText( TheReturnString );
  2472.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2473.   FTPCommandInProgress := false;
  2474.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2475.   begin
  2476.     { Do clever C formatting trick }
  2477.     TheReturnString :=
  2478.      DoCStyleFormat( 'Create Directory %s Failed!' ,
  2479.       [ TheDir ] );
  2480.     { Put result in progress and status line }
  2481.     AddProgressText( TheReturnString );
  2482.     ShowProgressErrorText( TheReturnString );
  2483.     { Signal error }
  2484.     Result := False;
  2485.     { leave }
  2486.     exit;
  2487.   end
  2488.   else Result := true; { Signal no problem }
  2489. end;
  2490.  
  2491.  
  2492. function TFTPComponent.DeleteRemoteFile( TheFileName : String ) : Boolean;
  2493. var TheReturnString : String;  { Internal string holder }
  2494.     TheResult       : Integer; { Internal int holder    }
  2495. begin
  2496.   TheReturnString := DoCStyleFormat( 'DELE %s' ,
  2497.     [ TheFileName ] );
  2498.   { Put result in progress and status line }
  2499.   AddProgressText( TheReturnString );
  2500.   ShowProgressText( TheReturnString );
  2501.   { Send Password sequence }
  2502.   TheResult := PerformFTPCommand( 'DELE %s',
  2503.                                   [ TheFileName ] );
  2504.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2505.   begin
  2506.     Result := false;
  2507.     FTPCommandInProgress := false;
  2508.     exit;
  2509.   end;
  2510.   repeat
  2511.     TheResult := GetFTPServerResponse( TheReturnString );
  2512.     { Put result in progress and status line }
  2513.     AddProgressText( TheReturnString );
  2514.     ShowProgressText( TheReturnString );
  2515.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2516.   FTPCommandInProgress := false;
  2517.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2518.   begin
  2519.     { Do clever C formatting trick }
  2520.     TheReturnString :=
  2521.      DoCStyleFormat( 'Delete File %s Failed!' ,
  2522.       [ TheFileName ] );
  2523.     { Put result in progress and status line }
  2524.     AddProgressText( TheReturnString );
  2525.     ShowProgressErrorText( TheReturnString );
  2526.     { Signal error }
  2527.     Result := False;
  2528.     { leave }
  2529.     exit;
  2530.   end
  2531.   else Result := true; { Signal no problem }
  2532. end;
  2533.  
  2534. { This is the FTP components PASSWORD routine }
  2535. function TFTPComponent.SendPassword(
  2536.           PCRPointer : PConnectionsRecord ) : Boolean;
  2537. var TheReturnString : String;  { Internal string holder }
  2538.     TheResult       : Integer; { Internal int holder    }
  2539. begin
  2540.   TheReturnString := 'PASS XXXXXX' + #13#10;
  2541.   { Put result in progress and status line }
  2542.   AddProgressText( TheReturnString );
  2543.   ShowProgressText( TheReturnString );
  2544.   { Send Password sequence }
  2545.   TheResult := PerformFTPCommand( 'PASS %s',
  2546.                                   [ PCRPointer^.CPassword ] );
  2547.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2548.   begin
  2549.     Result := false;
  2550.     FTPCommandInProgress := false;
  2551.     exit;
  2552.   end;
  2553.   repeat
  2554.     TheResult := GetFTPServerResponse( TheReturnString );
  2555.     { Put result in progress and status line }
  2556.     AddProgressText( TheReturnString );
  2557.     ShowProgressText( TheReturnString );
  2558.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2559.   FTPCommandInProgress := false;
  2560.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2561.   begin
  2562.     { Do clever C formatting trick }
  2563.     TheReturnString :=
  2564.      DoCStyleFormat( 'FTP Host %s Connection Failed!' ,
  2565.       [ PCRPointer^.CIPAddress ] );
  2566.     { Put result in progress and status line }
  2567.     AddProgressText( TheReturnString );
  2568.     ShowProgressErrorText( TheReturnString );
  2569.     { Signal error }
  2570.     Result := False;
  2571.     { leave }
  2572.     exit;
  2573.   end
  2574.   else Result := true; { Signal no problem }
  2575. end;
  2576.  
  2577. { This is the FTP components CWD routine }
  2578. function TFTPComponent.SetRemoteStartupDirectory(
  2579.           PCRPointer : PConnectionsRecord ) : Boolean;
  2580. var TheReturnString : String;  { Internal string holder }
  2581.     TheResult       : Integer; { Internal int holder    }
  2582. begin
  2583.   Result := true;
  2584.   if PCRPointer^.CStartDir <> '' then
  2585.   begin
  2586.     TheReturnString :=
  2587.      DoCStyleFormat( 'CWD %s' ,
  2588.       [ PCRPointer^.CStartDir ] );
  2589.     { Put result in progress and status line }
  2590.     AddProgressText( TheReturnString );
  2591.     ShowProgressText( TheReturnString );
  2592.     { Send Password sequence }
  2593.     TheResult := PerformFTPCommand( 'CWD %s',
  2594.                                     [ PCRPointer^.CStartDir ] );
  2595.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2596.     begin
  2597.       Result := false;
  2598.       FTPCommandInProgress := false;
  2599.       exit;
  2600.     end;
  2601.     repeat
  2602.       TheResult := GetFTPServerResponse( TheReturnString );
  2603.       { Put result in progress and status line }
  2604.       AddProgressText( TheReturnString );
  2605.       ShowProgressText( TheReturnString );
  2606.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2607.    FTPCommandInProgress := false;
  2608.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2609.     begin
  2610.       { Do clever C formatting trick }
  2611.       TheReturnString :=
  2612.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2613.         [ PCRPointer^.CStartDir ] );
  2614.       { Put result in progress and status line }
  2615.       AddProgressText( TheReturnString );
  2616.       ShowProgressErrorText( TheReturnString );
  2617.       { Signal error }
  2618.       Result := False;
  2619.       { leave }
  2620.       exit;
  2621.     end
  2622.     else Result := true; { Signal no problem }
  2623.   end;
  2624. end;
  2625.  
  2626. { This is the FTP components CWD routine }
  2627. function TFTPComponent.SetRemoteDirectory( TheDir : String ) : Boolean;
  2628. var TheReturnString : String;  { Internal string holder }
  2629.     TheResult       : Integer; { Internal int holder    }
  2630. begin
  2631.   Result := true;
  2632.   if TheDir <> '' then
  2633.   begin
  2634.     TheReturnString :=
  2635.      DoCStyleFormat( 'CWD %s' ,
  2636.       [ TheDir ] );
  2637.     { Put result in progress and status line }
  2638.     AddProgressText( TheReturnString );
  2639.     ShowProgressText( TheReturnString );
  2640.     { Send Password sequence }
  2641.     TheResult := PerformFTPCommand( 'CWD %s',
  2642.                                     [ TheDir ] );
  2643.     if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2644.     begin
  2645.       Result := false;
  2646.       FTPCommandInProgress := false;
  2647.       exit;
  2648.     end;
  2649.     repeat
  2650.       TheResult := GetFTPServerResponse( TheReturnString );
  2651.       { Put result in progress and status line }
  2652.       AddProgressText( TheReturnString );
  2653.       ShowProgressText( TheReturnString );
  2654.    until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2655.    FTPCommandInProgress := false;
  2656.    if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2657.     begin
  2658.       { Do clever C formatting trick }
  2659.       TheReturnString :=
  2660.        DoCStyleFormat( 'CWD to %s Failed!' ,
  2661.         [ TheDir ] );
  2662.       { Put result in progress and status line }
  2663.       AddProgressText( TheReturnString );
  2664.       ShowProgressErrorText( TheReturnString );
  2665.       { Signal error }
  2666.       Result := False;
  2667.       { leave }
  2668.       exit;
  2669.     end
  2670.     else Result := true; { Signal no problem }
  2671.   end;
  2672. end;
  2673.  
  2674. { This is the FTP components QUIT routine }
  2675. function TFTPComponent.Disconnect : Boolean;
  2676. var TheReturnString : String;  { Internal string holder }
  2677.     TheResult       : Integer; { Internal int holder    }
  2678. begin
  2679.   TheReturnString :=
  2680.    DoCStyleFormat( 'QUIT' ,
  2681.     [ nil ] );
  2682.   { Put result in progress and status line }
  2683.   AddProgressText( TheReturnString );
  2684.   ShowProgressText( TheReturnString );
  2685.   { Begin login sequence with user name }
  2686.   PerformFTPCommand( 'QUIT', [ nil ] );
  2687.   repeat
  2688.     TheResult := GetFTPServerResponse( TheReturnString );
  2689.     { Put result in progress and status line }
  2690.     AddProgressText( TheReturnString );
  2691.     ShowProgressText( TheReturnString );
  2692.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2693.   FTPCommandInProgress := false;
  2694.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2695.   begin
  2696.     { Do clever C formatting trick }
  2697.     TheReturnString :=
  2698.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2699.       [ nil ] );
  2700.     { Put result in progress and status line }
  2701.     AddProgressText( TheReturnString );
  2702.     ShowProgressErrorText( TheReturnString );
  2703.     { Signal error }
  2704.     Result := False;
  2705.     { leave }
  2706.     exit;
  2707.   end
  2708.   else Result := true; { Signal no problem }
  2709. end;
  2710.  
  2711. { This is the FTP components PWD routine }
  2712. function TFTPComponent.GetRemoteWorkingDirectory( var RemoteDir : String )
  2713.           : Boolean;
  2714. var TheReturnString : String;  { Internal string holder }
  2715.     TheResult       : Integer; { Internal int holder    }
  2716. begin
  2717.   TheReturnString :=
  2718.    DoCStyleFormat( 'PWD' ,
  2719.     [ nil ] );
  2720.   { Put result in progress and status line }
  2721.   AddProgressText( TheReturnString );
  2722.   ShowProgressText( TheReturnString );
  2723.   { Send Password sequence }
  2724.   TheResult := PerformFTPCommand( 'PWD',
  2725.                                   [ nil ] );
  2726.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2727.   begin
  2728.     Result := false;
  2729.     FTPCommandInProgress := false;
  2730.     exit;
  2731.   end;
  2732.   repeat
  2733.     TheResult := GetFTPServerResponse( TheReturnString );
  2734.     { Put result in progress and status line }
  2735.     AddProgressText( TheReturnString );
  2736.     ShowProgressText( TheReturnString );
  2737.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2738.   FTPCommandInProgress := false;
  2739.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2740.   begin
  2741.     { Do clever C formatting trick }
  2742.     TheReturnString :=
  2743.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2744.       [ nil ] );
  2745.     { Put result in progress and status line }
  2746.     AddProgressText( TheReturnString );
  2747.     ShowProgressErrorText( TheReturnString );
  2748.     { Signal error }
  2749.     Result := False;
  2750.     { leave }
  2751.     exit;
  2752.   end
  2753.   else
  2754.   begin
  2755.     Result := true; { Signal no problem }
  2756.     RemoteDir := TheReturnString; { Send back last string on faith }
  2757.   end;
  2758. end;
  2759.  
  2760. { This function sets up a listening port on socekt 2 and handle text replies }
  2761. function TFTPComponent.GetListeningPort : Integer;
  2762. var
  2763.   Address1 ,
  2764.   Address2 ,
  2765.   Address3 ,
  2766.   Address4        : integer; { Address integer conversions }
  2767.   IPAddress       : string;  { IP Address holder           }
  2768.   PortCommand     : string;  { Command holder              }
  2769.   TheResult       : Integer; { Result holder               }
  2770.   TheReturnString : String;  { ditto                       }
  2771. begin
  2772.   { Set up any port on socket 2 }
  2773.   Socket2.PortName := '0';
  2774.   { Listen on a socket }
  2775.   Socket2.CCSockListen;
  2776.   { Get the IP Address of socket 1 and convert it to numbers }
  2777.   IPAddress := Socket1.GetSocketIPAddress( Socket1.TheSocket );
  2778.   Address1 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2779.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2780.   Address2 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress) -1 ));
  2781.   IPAddress := copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 );
  2782.   Address3 := StrToInt( copy( IPAddress , 1 , Pos( '.' , IPAddress ) -1 ));
  2783.   Address4 := StrToInt( copy( IPAddress , Pos( '.' , IPAddress ) + 1 , 255 ));
  2784.   { Turn it into a command and add socket 2 stuff }
  2785.   PortCommand := format( 'PORT %d,%d,%d,%d,%d,%d' ,
  2786.    [ Address1 , Address2 , Address3 , Address4 ,
  2787.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) Shr 8,
  2788.     StrToInt( Socket2.GetSocketPort( Socket2.TheMasterSocket )) and $ff ]);
  2789.   { Put result in progress and status line }
  2790.   AddProgressText( PortCommand + #13#10 );
  2791.   ShowProgressText( PortCommand  + #13#10 );
  2792.   TheResult := PerformFTPCommand( PortCommand , [nil] );
  2793.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2794.   begin
  2795.     Result := TCPIP_STATUS_FATAL_ERROR;
  2796.     FTPCommandInProgress := false;
  2797.     exit;
  2798.   end;
  2799.   repeat
  2800.     TheResult := GetFTPServerResponse( TheReturnString );
  2801.     { Put result in progress and status line }
  2802.     AddProgressText( TheReturnString );
  2803.     ShowProgressText( TheReturnString );
  2804.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2805.   FTPCommandInProgress := false;
  2806.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2807.   begin
  2808.     { Do clever C formatting trick }
  2809.     TheReturnString :=
  2810.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2811.       [ nil ] );
  2812.     { Put result in progress and status line }
  2813.     AddProgressText( TheReturnString );
  2814.     ShowProgressErrorText( TheReturnString );
  2815.     { Signal error }
  2816.     Result := TheResult;
  2817.     { leave }
  2818.     exit;
  2819.   end
  2820.   else
  2821.   begin
  2822.     { Return good result and leave }
  2823.     Result := TheResult;
  2824.     exit;
  2825.   end;
  2826. end;
  2827.  
  2828. { This function returns part of a unit text string }
  2829. function TFTPComponent.GetUNIXTextString( var StringIn : String ) : String;
  2830. var
  2831.   ReturnString : String;
  2832.   TheLength ,
  2833.   Counter_1   : integer;
  2834. begin
  2835.   TheLength := Length( StringIn );
  2836.   if TheLength > 1 then
  2837.   begin
  2838.     for Counter_1 := 1 to TheLength do
  2839.     begin
  2840.       if StringIn[ Counter_1 ] = #10 then
  2841.       begin
  2842.         ReturnString := HolderLine;
  2843.         HolderLine := '';
  2844.         StringIn := Copy( StringIn , Counter_1 + 1 , 255 );
  2845.         Result := ReturnString;
  2846.         exit;
  2847.       end
  2848.       else
  2849.       begin
  2850.         if StringIn[ Counter_1 ] <> #0 then
  2851.         begin
  2852.           if StringIn[ Counter_1 ] <> #13 then
  2853.            HolderLine := HolderLine + StringIn[ Counter_1 ];
  2854.         end
  2855.         else
  2856.         begin
  2857.           Result := '';
  2858.           StringIn := '';
  2859.         end;
  2860.       end;
  2861.     end;
  2862.   end;
  2863.   Result := '';
  2864.   StringIn := '';
  2865. end;
  2866.  
  2867. procedure TFTPComponent.GetFileNameFromUNIXFileName( var TheName : String );
  2868. var Counter_1 : Integer;
  2869.     ResultString : String;
  2870.     Finished : Boolean;
  2871. begin
  2872.   if Pos( 'TOTAL' , Uppercase( TheName )) <> 0 then
  2873.   begin
  2874.     TheName := '';
  2875.     exit;
  2876.   end;
  2877.   Counter_1 := Length( TheName );
  2878.   ResultString := '';
  2879.   Finished := false;
  2880.   while not Finished do
  2881.   begin
  2882.     if TheName[ Counter_1 ] <> ' ' then
  2883.     begin
  2884.       Counter_1 := Counter_1 - 1;
  2885.       if Counter_1 = 0 then
  2886.       begin
  2887.         ResultString := TheName;
  2888.         Finished := true;
  2889.       end;
  2890.     end
  2891.     else
  2892.     begin
  2893.       Finished := true;
  2894.       ResultString := Copy( TheName , Counter_1 + 1 , 255 );
  2895.     end;
  2896.   end;
  2897.   TheName := ResultString;
  2898. end;
  2899.  
  2900. { This is the FTP components get remote directory listing into a list box }
  2901. function TFTPComponent.GetRemoteDirectoryListing( TheListBox : TListBox )
  2902.           : Boolean;
  2903. var TheReturnString : String;  { Internal string holder }
  2904.     TheResult       : Integer; { Internal int holder    }
  2905.     InputString     : String;
  2906.     Through ,
  2907.     Finished        : Boolean;
  2908. begin
  2909.   TheListBox.Clear;
  2910.   TheListbox.Tag := 2;
  2911.   TheListBox.Items.Add('..');
  2912.   Result := true;
  2913.   TheReturnString :=
  2914.    DoCStyleFormat( 'TYPE A' ,
  2915.     [ nil ] );
  2916.   { Put result in progress and status line }
  2917.   AddProgressText( TheReturnString );
  2918.   ShowProgressText( TheReturnString );
  2919.   { Send Password sequence }
  2920.   TheResult := PerformFTPCommand( 'TYPE A',
  2921.                                   [ nil ] );
  2922.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  2923.   begin
  2924.     Result := true;
  2925.     FTPCommandInProgress := false;
  2926.     exit;
  2927.   end;
  2928.   repeat
  2929.     TheResult := GetFTPServerResponse( TheReturnString );
  2930.     { Put result in progress and status line }
  2931.     AddProgressText( TheReturnString );
  2932.     ShowProgressText( TheReturnString );
  2933.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  2934.   FTPCommandInProgress := false;
  2935.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  2936.   begin
  2937.     { Do clever C formatting trick }
  2938.     TheReturnString :=
  2939.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  2940.       [ nil ] );
  2941.     { Put result in progress and status line }
  2942.     AddProgressText( TheReturnString );
  2943.     ShowProgressErrorText( TheReturnString );
  2944.     { Signal error }
  2945.     Result := true;
  2946.     { leave }
  2947.     exit;
  2948.   end
  2949.   else
  2950.   begin
  2951.     { Set up socket 2 for listening }
  2952.     Socket2.AsynchMode := False;
  2953.     Socket2.NonAsynchTimeoutValue := 60;
  2954.     { do a listen and send command to server that this is receipt socket }
  2955.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  2956.     begin
  2957.       Socket2.CCSockCancelListen;
  2958.       exit;
  2959.     end;
  2960.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  2961.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  2962.     GetFTPServerResponse( TheReturnString );
  2963.     AddProgressText( TheReturnString );
  2964.     ShowProgressText( TheReturnString );
  2965.     Socket1.NonAsynchTimeoutValue := 30;
  2966.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  2967.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  2968.     begin
  2969.       TheReturnString :=
  2970.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  2971.         [ nil ] );
  2972.       { Put result in progress and status line }
  2973.       AddProgressText( TheReturnString );
  2974.       ShowProgressErrorText( TheReturnString );
  2975.       Socket2.CCSockCancelListen;
  2976.       Result := true;
  2977.       exit;
  2978.     end;
  2979.     Socket2.CCSockAccept;
  2980.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  2981.     begin
  2982.       TheReturnString :=
  2983.        DoCStyleFormat( 'Could not establish receive socket!' ,
  2984.         [ nil ] );
  2985.       { Put result in progress and status line }
  2986.       AddProgressText( TheReturnString );
  2987.       ShowProgressErrorText( TheReturnString );
  2988.       Result := true;
  2989.       exit;
  2990.     end;
  2991.     Through := false;
  2992.     repeat
  2993.       TheReturnString := Socket2.StringData;
  2994.       if Length( TheReturnString ) = 0 then Through := true;
  2995.       if Length( TheReturnString ) > 0 then
  2996.       begin
  2997.         finished := false;
  2998.         while not finished do
  2999.         begin
  3000.           InputString := GetUNIXTextString( TheReturnString );
  3001.           if InputString = '' then Finished := true else
  3002.           begin
  3003.             GetFileNameFromUNIXFileName( InputString);
  3004.             If InputString <> '' then
  3005.             TheListBox.Items.Add( InputString );
  3006.           end;
  3007.         end;
  3008.       end;
  3009.       if GlobalAbortedFlag then
  3010.       begin
  3011.         Socket1.OutOfBand := 'ABOR'+#13#10;
  3012.         repeat
  3013.           TheResult := GetFTPServerResponse( TheReturnString );
  3014.           { Put result in progress and status line }
  3015.           AddProgressText( TheReturnString );
  3016.           ShowProgressText( TheReturnString );
  3017.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3018.         result := true;
  3019.         exit;
  3020.       end;
  3021.     until Through;
  3022.     GetFTPServerResponse( TheReturnString );
  3023.     AddProgressText( TheReturnString );
  3024.     ShowProgressText( TheReturnString );
  3025.     { cancel listening on second socket and close it }
  3026.     Socket2.CCSockCancelListen;
  3027.     Socket2.CCSockClose;
  3028.   end;
  3029.   FTPCommandInProgress := false;
  3030. end;
  3031.  
  3032. { This is the FTP components get remote directory listing into a list box }
  3033. function TFTPComponent.GetRemoteDirectoryListingToMemo : Boolean;
  3034. var TheReturnString : String;  { Internal string holder }
  3035.     TheResult       : Integer; { Internal int holder    }
  3036.     Through         : Boolean;
  3037. begin
  3038.   Result := true;
  3039.   TheReturnString :=
  3040.    DoCStyleFormat( 'TYPE A' ,
  3041.     [ nil ] );
  3042.   { Put result in progress and status line }
  3043.   AddProgressText( TheReturnString );
  3044.   ShowProgressText( TheReturnString );
  3045.   { Send Password sequence }
  3046.   TheResult := PerformFTPCommand( 'TYPE A',
  3047.                                   [ nil ] );
  3048.   if TheResult <> TCPIP_STATUS_PRELIMINARY then
  3049.   begin
  3050.     Result := true;
  3051.     FTPCommandInProgress := false;
  3052.     exit;
  3053.   end;
  3054.   repeat
  3055.     TheResult := GetFTPServerResponse( TheReturnString );
  3056.     { Put result in progress and status line }
  3057.     AddProgressText( TheReturnString );
  3058.     ShowProgressText( TheReturnString );
  3059.   until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3060.   FTPCommandInProgress := false;
  3061.   if ( GlobalAbortedFlag or ( TheResult <> TCPIP_STATUS_COMPLETED )) then
  3062.   begin
  3063.     { Do clever C formatting trick }
  3064.     TheReturnString :=
  3065.      DoCStyleFormat( 'FTP Host Connection Failed!' ,
  3066.       [ nil ] );
  3067.     { Put result in progress and status line }
  3068.     AddProgressText( TheReturnString );
  3069.     ShowProgressErrorText( TheReturnString );
  3070.     { Signal error }
  3071.     Result := true;
  3072.     { leave }
  3073.     exit;
  3074.   end
  3075.   else
  3076.   begin
  3077.     { Set up socket 2 for listening }
  3078.     Socket2.AsynchMode := False;
  3079.     Socket2.NonAsynchTimeoutValue := 30;
  3080.     { do a listen and send command to server that this is receipt socket }
  3081.     if GetListeningPort = TCPIP_STATUS_FATAL_ERROR then
  3082.     begin
  3083.       Socket2.CCSockCancelListen;
  3084.       exit;
  3085.     end;
  3086.     Socket1.NonAsynchTimeoutValue := 0; {infinite timeout}
  3087.     TheResult := PerformFTPCommand( 'LIST' , [nil] );
  3088.     GetFTPServerResponse( TheReturnString );
  3089.     AddProgressText( TheReturnString );
  3090.     ShowProgressText( TheReturnString );
  3091.     Socket1.NonAsynchTimeoutValue := 30;
  3092.     if (( TheResult = TCPIP_STATUS_RETRY_COMMAND ) or
  3093.        ( TheResult = TCPIP_STATUS_FATAL_ERROR )) then
  3094.     begin
  3095.       TheReturnString :=
  3096.        DoCStyleFormat( 'Could not obtain remote directory!' ,
  3097.         [ nil ] );
  3098.       { Put result in progress and status line }
  3099.       AddProgressText( TheReturnString );
  3100.       ShowProgressErrorText( TheReturnString );
  3101.       Socket2.CCSockCancelListen;
  3102.       Result := true;
  3103.       exit;
  3104.     end;
  3105.     Socket2.CCSockAccept;
  3106.     if (( GlobalAbortedFlag ) or ( GlobalErrorCode <> 0 )) then
  3107.     begin
  3108.       TheReturnString :=
  3109.        DoCStyleFormat( 'Could not establish receive socket!' ,
  3110.         [ nil ] );
  3111.       { Put result in progress and status line }
  3112.       AddProgressText( TheReturnString );
  3113.       ShowProgressErrorText( TheReturnString );
  3114.       Result := true;
  3115.       exit;
  3116.     end;
  3117.     Through := false;
  3118.     repeat
  3119.       TheReturnString := Socket2.StringData;
  3120.       if Length( TheReturnString ) = 0 then Through := true;
  3121.       if Length( TheReturnString ) > 0 then
  3122.       begin
  3123.         { Put result in progress and status line }
  3124.         AddProgressText( TheReturnString );
  3125.         ShowProgressText( TheReturnString );
  3126.       end;
  3127.       if GlobalAbortedFlag then
  3128.       begin
  3129.         Socket1.OutOfBand := 'ABOR'+#13#10;
  3130.         repeat
  3131.           TheResult := GetFTPServerResponse( TheReturnString );
  3132.           { Put result in progress and status line }
  3133.           AddProgressText( TheReturnString );
  3134.           ShowProgressText( TheReturnString );
  3135.         until (( GlobalAbortedFlag ) or ( TheResult <> TCPIP_STATUS_PRELIMINARY ));
  3136.         result := true;
  3137.         exit;
  3138.       end;
  3139.     until Through;
  3140.     GetFTPServerResponse( TheReturnString );
  3141.     AddProgressText( TheReturnString );
  3142.     ShowProgressText( TheReturnString );
  3143.     { cancel listening on second socket and close it }
  3144.     Socket2.CCSockCancelListen;
  3145.     Socket2.CCSockClose;
  3146.   end;
  3147. end;
  3148.  
  3149. { This is the FTP components get local directory listing into a list box }
  3150. function TFTPComponent.GetLocalDirectoryAndListing( var TheString : String;
  3151.                                                         TheListBox : TListBox )
  3152.           : Boolean;
  3153. var TheFLB : TFileListBox;
  3154. begin
  3155.   { Get the working directory }
  3156.   GetDir( 0 , TheString );
  3157.   { Clear incoming LB }
  3158.   TheListBox.Clear;
  3159.   TheListBox.Tag := 2;
  3160.   TheFLB := TFileListBox.Create( Application.MainForm );
  3161.   TheFLB.Visible := false;
  3162.   TheFLB.Parent := Application.MainForm;
  3163.   TheFLB.FileType := [ ftNormal , ftDirectory ];
  3164.   TheFLB.Directory := TheString;
  3165.   TheFLB.Update;
  3166.   TheListBox.Items.Assign( TheFLB.Items );
  3167.   TheFLB.Free;
  3168.   result := true;
  3169. end;
  3170.  
  3171. { This is a clever c-style formatting trick }
  3172. function TFTPComponent.DoCStyleFormat(
  3173.                 TheText      : string;
  3174.           const TheArguments : array of const ) : String;
  3175. begin
  3176.   Result := Format( TheText , TheArguments ) + #13#10;
  3177. end;
  3178.  
  3179. function TFTPComponent.GetQuotedString( TheString : String ) : String;
  3180. var TheIndex     : Integer; { Holder var }
  3181.     ResultString : String;  { ditto      }
  3182. begin
  3183.   { Find out if " present at all }
  3184.   TheIndex := Pos( '"' , TheString );
  3185.   If TheIndex = 0 then
  3186.   begin
  3187.     { If not, return null string and exit }
  3188.     Result := '';
  3189.     exit;
  3190.   end
  3191.   else
  3192.   begin
  3193.     { Get from first " to end of string in holder }
  3194.     ResultString := Copy( TheString , TheIndex + 1 , 255 );
  3195.     { Find position to second " }
  3196.     TheIndex := Pos( '"' , ResultString );
  3197.     { If no ending " then return whole string and leave }
  3198.     if TheIndex = 0 then
  3199.     begin
  3200.       Result := ResultString;
  3201.       exit;
  3202.     end
  3203.     else
  3204.     begin
  3205.       { Get internal text between quotes and exit }
  3206.       ResultString := Copy( ResultString , 1 , TheIndex - 1 );
  3207.       Result := ResultString;
  3208.     end;
  3209.   end;
  3210. end;
  3211.  
  3212. procedure TCCINetCCForm.UpdateGauge( BytesFinished , TotalToHandle : longint );
  3213. var
  3214.   Percentage : longint;
  3215. begin
  3216.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3217.   if TotalToHandle = 0 then exit;
  3218.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3219.   Gauge1.Progress := Percentage;
  3220.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3221.    ' bytes ' + FileNameToXFer + ' (' + IntToStr( Percentage ) + '% Done)';
  3222. end;
  3223.  
  3224. procedure TCCINetCCForm.UpdateMailGauge( BytesFinished , TotalToHandle : longint );
  3225. var
  3226.   Percentage : longint;
  3227. begin
  3228.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3229.   if TotalToHandle = 0 then exit;
  3230.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3231.   Gauge1.Progress := Percentage;
  3232.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3233.    ' bytes mail (' + IntToStr( Percentage ) + '% Done)';
  3234. end;
  3235.  
  3236. procedure TCCINetCCForm.UpdateMIMEGauge( BytesFinished , TotalToHandle : longint );
  3237. var
  3238.   Percentage : longint;
  3239. begin
  3240.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3241.   if TotalToHandle = 0 then exit;
  3242.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3243.   Gauge1.Progress := Percentage;
  3244.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3245.    ' bytes MIME (' + IntToStr( Percentage ) + '% Done)';
  3246. end;
  3247.  
  3248. procedure TCCINetCCForm.UpdateUUGauge( BytesFinished , TotalToHandle : longint );
  3249. var
  3250.   Percentage : longint;
  3251. begin
  3252.   if BytesFinished > TotalToHandle then BytesFinished := TotalToHandle;
  3253.   if TotalToHandle = 0 then exit;
  3254.   Percentage := Trunc( 100.0 / ( TotalToHandle / BytesFinished ));
  3255.   Gauge1.Progress := Percentage;
  3256.   Panel1.Caption := '  Status: ' + IntToStr( BytesFinished ) +
  3257.    ' bytes UUCode (' + IntToStr( Percentage ) + '% Done)';
  3258.   Panel1.Show;
  3259. end;
  3260.  
  3261. { This procedure actually attempts to connect to the internet at an ftp site }
  3262. function TCCINetCCForm.DoFTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3263. var TheReturnString : String; { Display results of connection in status lines }
  3264. begin
  3265.   { Create the component }
  3266.   Result := false;
  3267.   { Do busy cursors }
  3268.   SetHGCursors;
  3269.   if not TheFTPComponent.EstablishConnection( PCRPointer ) then
  3270.   begin
  3271.     { Do saved cursors }
  3272.     TheFTPComponent.FTPCommandInProgress := false;
  3273.     TheFTPComponent.Connection_Established := false;
  3274.     SetNormalCursors;
  3275.     exit;
  3276.   end
  3277.   else
  3278.   begin { Connected; continue login process }
  3279.     if not TheFTPComponent.LoginUser( PCRPointer ) then
  3280.     begin
  3281.       { Do saved cursors }
  3282.       TheFTPComponent.FTPCommandInProgress := false;
  3283.       TheFTPComponent.Connection_Established := false;
  3284.       SetNormalCursors;
  3285.       exit;
  3286.     end;
  3287.     if not TheFTPComponent.SendPassword( PCRPointer ) then
  3288.     begin
  3289.       { Do saved cursors }
  3290.       TheFTPComponent.FTPCommandInProgress := false;
  3291.       TheFTPComponent.Connection_Established := false;
  3292.       SetNormalCursors;
  3293.       exit;
  3294.     end;
  3295.     if not TheFTPComponent.SetRemoteStartupDirectory( PCRPointer ) then
  3296.     begin
  3297.       { Do saved cursors }
  3298.       SetNormalCursors;
  3299.       TheFTPComponent.Connection_Established := false;
  3300.       TheFTPComponent.FTPCommandInProgress := false;
  3301.       exit;
  3302.     end;
  3303.     if not TheFTPComponent.GetRemoteWorkingDirectory( TheReturnString ) then
  3304.     begin
  3305.       { Do saved cursors }
  3306.       TheFTPComponent.Connection_Established := false;
  3307.       TheFTPComponent.FTPCommandInProgress := false;
  3308.       SetNormalCursors;
  3309.       exit;
  3310.     end;
  3311.     { Put up remote directory via PWD and strip quotes }
  3312.     Label4.Caption := TheFTPComponent.GetQuotedString( TheReturnString );
  3313.     { Get the listings of directories and exit OK }
  3314.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  3315.     TheFTPComponent.GetLocalDirectoryAndListing( TheReturnString ,
  3316.      Listbox2 );
  3317.     if Label5.Canvas.TextWidth( TheReturnString ) > Label5.Width then
  3318.      TheReturnString := TheFTPComponent.GetShortPathName( TheReturnString );
  3319.     Label5.Caption := TheReturnString;
  3320.     SetNormalCursors;
  3321.     Result := true;
  3322.     EnableFTPMenus;
  3323.     TheFTPComponent.FTPCommandInProgress := false;
  3324.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3325.   end;
  3326. end;
  3327.  
  3328. { This procedure actually attempts to connect to the internet at an nntp site }
  3329. function TCCINetCCForm.DoNNTPConnection( PCRPointer : PConnectionsRecord ) : boolean;
  3330. begin
  3331.   { Create the component }
  3332.   Result := false;
  3333.   { Do busy cursors }
  3334.   SetHGCursors;
  3335.   if not TheNNTPComponent.EstablishConnection( PCRPointer ) then
  3336.   begin
  3337.     { Do saved cursors }
  3338.     TheNNTPComponent.NNTPCommandInProgress := false;
  3339.     TheNNTPComponent.Connection_Established := false;
  3340.     SetNormalCursors;
  3341.     exit;
  3342.   end
  3343.   else
  3344.   begin { Connected; continue login process }
  3345.     SetNormalCursors;
  3346.     Result := true;
  3347.     EnableNNTPMenus;
  3348.     TheNNTPComponent.NNTPCommandInProgress := false;
  3349.     Panel1.Caption := '  Status : Connected to ' + PCRPointer^.CIPAddress;
  3350.   end;
  3351. end;
  3352.  
  3353. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3354. procedure TCCINetCCForm.DoFTPDisconnect;
  3355. begin
  3356.   { Call QUIT command }
  3357.   TheFTPComponent.Disconnect;
  3358.   { Kill the socket }
  3359.   TheFTPComponent.Socket1.CCSockClose;
  3360. end;
  3361.  
  3362. { This procedure actually attempts to disconnect to the internet at an ftp site}
  3363. procedure TCCINetCCForm.DoNNTPDisconnect;
  3364. begin
  3365.   { Call QUIT command }
  3366.   TheNNTPComponent.Disconnect;
  3367.   { Kill the socket }
  3368.   TheNNTPComponent.Socket1.CCSockClose;
  3369. end;
  3370.  
  3371. { This procedure reads in the ini file and default path info }
  3372. procedure TCCINetCCForm.ReadIniData;
  3373. begin
  3374.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3375.   MailPath := TheICCIniFile.ReadString( 'Paths','MailPath','C:\WINDOWS' );
  3376.   NewsPath := TheICCIniFile.ReadString( 'Paths','NewsPath','C:\WINDOWS' );
  3377.   FTPPath := TheICCIniFile.ReadString( 'Paths','FTPPath','C:\WINDOWS' );
  3378.   PasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','PWControl',2 );
  3379.   DefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','DefDL', 3 );
  3380.   TheAnonRedialVector := TheICCIniFile.ReadInteger( 'Vectors','AnonRD', 20 );
  3381.   NewsReadArticlePurgingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsPurge', 1 );
  3382.   NewsPostQueueingVector := TheICCIniFile.ReadInteger( 'Vectors','NewsQueue', 1 );
  3383.   NewsReadArticleDisplayVector := TheICCIniFile.ReadInteger( 'Vectors','NewsRDisp', 1 );
  3384.   NewsUUMIMEVector := TheICCIniFile.ReadInteger( 'Vectors','NewsUUMIME', 2 );
  3385.   NewsInitialUpdateVector := TheICCIniFile.ReadInteger( 'Vectors','NewsInitUD', 1 );
  3386.   EMPasswordControlVector := TheICCIniFile.ReadInteger( 'Vectors','EMPWControl', 1 );
  3387.   EMRemoteDeletionVector  := TheICCIniFile.ReadInteger( 'Vectors','EMRemDel', 2 );
  3388.   EMChokeVector           := TheICCIniFile.ReadInteger( 'Vectors','EMChoke', 1 );
  3389.   EMDefaultDownloadVector := TheICCIniFile.ReadInteger( 'Vectors','EMInitUD', 1 );
  3390.   EMQueueVector           := TheICCIniFile.ReadInteger( 'Vectors','EMQueue', 1 );
  3391.   TheICCIniFile.Free;
  3392. end;
  3393.  
  3394. { This procedure writes out default path data to the ini file }
  3395. procedure TCCINetCCForm.WriteIniData;
  3396. begin
  3397.   TheICCIniFile := TIniFile.Create( 'CCICC.INI' );
  3398.   TheICCIniFile.WriteString( 'Paths','MailPath', MailPath );
  3399.   TheICCIniFile.WriteString( 'Paths','NewsPath', NewsPath );
  3400.   TheICCIniFile.WriteString( 'Paths','FTPPath', FTPPath );
  3401.   TheICCIniFile.WriteInteger( 'Vectors','PWControl', PasswordControlVector );
  3402.   TheICCIniFile.WriteInteger( 'Vectors','DefDL', DefaultDownloadVector );
  3403.   TheICCIniFile.WriteInteger( 'Vectors','AnonRD', TheAnonRedialVector );
  3404.   TheICCIniFile.WriteInteger( 'Vectors','NewsPurge',
  3405.    NewsReadArticlePurgingVector );
  3406.   TheICCIniFile.WriteInteger( 'Vectors','NewsQueue', NewsPostQueueingVector );
  3407.   TheICCIniFile.WriteInteger( 'Vectors','NewsRDisp',
  3408.    NewsReadArticleDisplayVector );
  3409.   TheICCIniFile.WriteInteger( 'Vectors','NewsUUMIME', NewsUUMIMEVector );
  3410.   TheICCIniFile.WriteInteger( 'Vectors','NewsInitUD', NewsInitialUpdateVector );
  3411.   TheICCIniFile.WriteInteger( 'Vectors','EMPWControl', EMPasswordControlVector );
  3412.   TheICCIniFile.WriteInteger( 'Vectors','EMRemDel', EMRemoteDeletionVector );
  3413.   TheICCIniFile.WriteInteger( 'Vectors','EMChoke', EMChokeVector );
  3414.   TheICCIniFile.WriteInteger( 'Vectors','EMInitUD', EMDefaultDownloadVector );
  3415.   TheICCIniFile.WriteInteger( 'Vectors','EMQueue', EMQueueVector );
  3416.   TheICCIniFile.Free;
  3417. end;
  3418.  
  3419. { Procedure to load the FTP Site list }
  3420. procedure TCCINetCCForm.LoadFTPSiteFile;
  3421. var TheTCRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3422.     FTPSLName   : String;             { FTP Site List filename }
  3423.     Counter_1   : Integer;            { Loop counter           }
  3424. begin
  3425.   { Create the sites list list }
  3426.   TheFTPSiteList := TList.Create;
  3427.   { Set up the FTP sites list file name }
  3428.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3429.   { If the FTP Site List exists load it in }
  3430.   if FileExists( FTPSLName ) then
  3431.   begin
  3432.     { set up the file and open it }
  3433.     AssignFile( TheFTPSiteFile , FTPSLName );
  3434.     Reset( TheFTPSiteFile );
  3435.     { read in the records }
  3436.     for Counter_1 := 0 to FileSize( TheFTPSiteFile ) - 1 do
  3437.     begin
  3438.       { Create the TCRecord }
  3439.       New( TheTCRecord );
  3440.       { Read in the data record }
  3441.       Seek( TheFTPSiteFile , Counter_1 );
  3442.       Read( TheFTPSiteFile , TheTCRecord^ );
  3443.       { Add the record to the list }
  3444.       TheFTPSiteList.Add( TheTCRecord );
  3445.     end;
  3446.     { close the file }
  3447.     CloseFile( TheFTPSiteFile );
  3448.   end
  3449.   else
  3450.   { Otherwise create a default one with a few anonymous sites }
  3451.   begin
  3452.     { create new record }
  3453.     New( TheTCRecord );
  3454.     { fill in its info }
  3455.     with TheTCRecord^ do
  3456.     begin
  3457.       CProfile   := 'Winsite Windows Archive';
  3458.       CIPAddress := 'ftp.winsite.com';
  3459.       CUserName  := 'anonymous';
  3460.       CPassword  := 'guest@nowhere.com';
  3461.       CStartDir  := '/pub';
  3462.     end;
  3463.     { add it to the list }
  3464.     { do it three more times }
  3465.     TheFTPSiteList.Add( TheTCRecord );
  3466.     New( TheTCRecord );
  3467.     with TheTCRecord^ do
  3468.     begin
  3469.       CProfile   := 'Digital Equipment Corp';
  3470.       CIPAddress := 'gatekeeper.dec.com';
  3471.       CUserName  := 'anonymous';
  3472.       CPassword  := 'guest@nowhere.com';
  3473.       CStartDir  := '/pub';
  3474.     end;
  3475.     TheFTPSiteList.Add( TheTCRecord );
  3476.     New( TheTCRecord );
  3477.     with TheTCRecord^ do
  3478.     begin
  3479.       CProfile   := 'Microsoft FTP Site';
  3480.       CIPAddress := 'ftp.microsoft.com';
  3481.       CUserName  := 'anonymous';
  3482.       CPassword  := 'guest@nowhere.com';
  3483.       CStartDir  := '/pub';
  3484.     end;
  3485.     TheFTPSiteList.Add( TheTCRecord );
  3486.     New( TheTCRecord );
  3487.     with TheTCRecord^ do
  3488.     begin
  3489.       CProfile   := 'Oakland MSDOS Archive';
  3490.       CIPAddress := 'oak.oakland.edu';
  3491.       CUserName  := 'anonymous';
  3492.       CPassword  := 'guest@nowhere.com';
  3493.       CStartDir  := '/pub';
  3494.     end;
  3495.     TheFTPSiteList.Add( TheTCRecord );
  3496.     { create the file and write out the data, then close it }
  3497.     AssignFile( TheFTPSiteFile , FTPSLName );
  3498.     Rewrite( TheFTPSiteFile );
  3499.     for Counter_1 := 0 to 3 do
  3500.     begin
  3501.       TheTCRecord :=
  3502.        PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3503.       Seek( TheFTPSiteFile , Counter_1 );
  3504.       Write( TheFTPSiteFile , TheTCRecord^ );
  3505.     end;
  3506.     CloseFile( TheFTPSiteFile );
  3507.   end;
  3508.   { Create the working copy for use to make safe changes in info dlg }
  3509.   TheWorkingFTPSL := TList.Create;
  3510.   For Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3511.   begin
  3512.     New( TheTCRecord );
  3513.     TheTCRecord^ := PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] )^;
  3514.     TheWorkingFTPSL.Add( TheTCRecord );
  3515.   end;
  3516. end;
  3517.  
  3518. { Procedure to load the NNTP Site list }
  3519. procedure TCCINetCCForm.LoadNNTPSiteFile;
  3520. var TheNGRecord : PConnectionsRecord; { Generic TCR Pointer    }
  3521.     NNTPSLName  : String;             { NNTP Site List filename }
  3522.     Counter_1   : Integer;            { Loop counter           }
  3523. begin
  3524.   { Create the sites list list }
  3525.   TheNewsServerList := TList.Create;
  3526.   { Set up the FTP sites list file name }
  3527.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3528.   { If the FTP Site List exists load it in }
  3529.   if FileExists( NNTPSLName ) then
  3530.   begin
  3531.     { set up the file and open it }
  3532.     AssignFile( TheNewsServerFile , NNTPSLName );
  3533.     Reset( TheNewsServerFile );
  3534.     { read in the records }
  3535.     for Counter_1 := 0 to FileSize( TheNewsServerFile ) - 1 do
  3536.     begin
  3537.       { Create the TCRecord }
  3538.       New( TheNGRecord );
  3539.       { Read in the data record }
  3540.       Seek( TheNewsServerFile , Counter_1 );
  3541.       Read( TheNewsServerFile , TheNGRecord^ );
  3542.       { Add the record to the list }
  3543.       TheNewsServerList.Add( TheNGRecord );
  3544.     end;
  3545.     { close the file }
  3546.     CloseFile( TheNewsServerFile );
  3547.   end
  3548.   else
  3549.   { Otherwise create a default one with a generic news site (?) }
  3550.   begin
  3551.     { create new record }
  3552.     New( TheNGRecord );
  3553.     { fill in its info }
  3554.     with TheNGRecord^ do
  3555.     begin
  3556.       CProfile   := 'My News Server';
  3557.       CIPAddress := 'news.myprovider.com';
  3558.       CUserName  := '';
  3559.       CPassword  := '';
  3560.       CStartDir  := '';
  3561.     end;
  3562.     { add it to the list }
  3563.     { do it three more times }
  3564.     TheNewsServerList.Add( TheNGRecord );
  3565.     { create the file and write out the data, then close it }
  3566.     AssignFile( TheNewsServerFile , NNTPSLName );
  3567.     Rewrite( TheNewsServerFile );
  3568.     TheNGRecord :=
  3569.        PConnectionsRecord( TheNewsServerList.Items[ 0 ] );
  3570.       Seek( TheNewsServerFile , 0 );
  3571.       Write( TheNewsServerFile , TheNGRecord^ );
  3572.     CloseFile( TheNewsServerFile );
  3573.   end;
  3574.   TheWorkingNSSL := TList.Create;
  3575.   For Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3576.   begin
  3577.     New( TheNGRecord );
  3578.     TheNGRecord^ := PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] )^;
  3579.     TheWorkingNSSL.Add( TheNGRecord );
  3580.   end;
  3581. end;
  3582.  
  3583. { This procedure saves off the FTP Site List }
  3584. procedure TCCINetCCForm.SaveFTPSiteFile;
  3585. var TheTCRecord : PConnectionsRecord; { The TC Record pointer  }
  3586.     FTPSLName   : String;             { FTP Site List filename }
  3587.     Counter_1   : Integer;            { Loop counter           }
  3588. begin
  3589.   { Set up the file name }
  3590.   FTPSLName := FTPPath + '\FTPSITES.TCR';
  3591.   { Assign the file }
  3592.   AssignFile( TheFTPSiteFile , FTPSLName );
  3593.   { Rewrite it }
  3594.   Rewrite( TheFTPSiteFile );
  3595.   { run the list through the procedure }
  3596.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3597.   begin
  3598.     { get the record from the list }
  3599.     TheTCRecord :=
  3600.      PConnectionsRecord( TheFTPSiteList.Items[ Counter_1 ] );
  3601.     { Do the seek/write }
  3602.     Seek( TheFTPSiteFile , Counter_1 );
  3603.     Write( TheFTPSiteFile , TheTCRecord^ );
  3604.     { free the record }
  3605.     Dispose( TheTCRecord );
  3606.   end;
  3607.   { Close the file }
  3608.   CloseFile( TheFTPSiteFile );
  3609.   { Free the list pointers }
  3610.   TheFTPSiteList.Free;
  3611.   TheWorkingFTPSL.Free;
  3612. end;
  3613.  
  3614. { This procedure saves off the FTP Site List }
  3615. procedure TCCINetCCForm.SaveNNTPSiteFile;
  3616. var TheNGRecord : PConnectionsRecord; { The TC Record pointer   }
  3617.     NNTPSLName   : String;            { NNTP Site List filename }
  3618.     Counter_1   : Integer;            { Loop counter           }
  3619. begin
  3620.   { Set up the file name }
  3621.   NNTPSLName := NewsPath + '\NNTPSITE.TCR';
  3622.   { Assign the file }
  3623.   AssignFile( TheNewsServerFile , NNTPSLName );
  3624.   { Rewrite it }
  3625.   Rewrite( TheNewsServerFile );
  3626.   { run the list through the procedure }
  3627.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  3628.   begin
  3629.     { get the record from the list }
  3630.     TheNGRecord :=
  3631.      PConnectionsRecord( TheNewsServerList.Items[ Counter_1 ] );
  3632.     { Do the seek/write }
  3633.     Seek( TheNewsServerFile , Counter_1 );
  3634.     Write( TheNewsServerFile , TheNGRecord^ );
  3635.     { free the record }
  3636.     Dispose( TheNGRecord );
  3637.   end;
  3638.   { Close the file }
  3639.   CloseFile( TheNewsServerFile );
  3640.   { Free the list pointers }
  3641.   TheNewsServerList.Free;
  3642.   TheWorkingNSSL.Free;
  3643. end;
  3644.  
  3645. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3646. procedure TCCINetCCForm.SetupFTPSiteLists;
  3647. var Counter_1  : Integer;            { Loop counter        }
  3648. begin
  3649.   { Set up display for main form }
  3650.   CCINetCCForm.Tag := 2;
  3651.   CCINetCCForm.Caption := 'CC Internet Command Center -- FTP Mode';
  3652.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3653.   CCINetCCForm.FTP1.Enabled := false;
  3654.   CCINetCCForm.FTP2.Enabled := true;
  3655.   CCINetCCForm.Label1.Caption := 'FTP Site:';
  3656.   CCINetCCForm.Button1.Caption := 'Connect';
  3657.   CCINetCCForm.Label4.Caption := 'Local Dir';
  3658.   CCINetCCForm.Label5.Caption := 'Remote Dir';
  3659.   { Set tag for FTP stuff }
  3660.   CCICInfoDlg.Tag := 2;
  3661.   { set up caption of main label }
  3662.   CCICInfoDlg.Label2.Caption := 'FTP Sites';
  3663.   { hide outline panel }
  3664.   CCICInfoDlg.Panel6.Visible := false;
  3665.   { clear the list box }
  3666.   CCICInfoDlg.ListBox2.Clear;
  3667.   CCINetCCForm.ComboBox1.Clear;
  3668.   { add profile strings to the list box }
  3669.   for Counter_1 := 0 to TheFTPSiteList.Count - 1 do
  3670.   begin
  3671.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  3672.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3673.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  3674.      TheFTPSiteList.Items[ Counter_1 ] )^.CProfile );
  3675.   end;
  3676.   { Set up caption of special button }
  3677.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  3678.   { Start with top record }
  3679.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  3680.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  3681.   { put in data from top record and reset captions }
  3682.   with PConnectionsRecord( TheFTPSiteList.Items[ 0 ] )^ do
  3683.   begin
  3684.     with CCICInfoDlg do
  3685.     begin
  3686.       Edit1.Text := CProfile;
  3687.       Panel2.Caption := '            Name:';
  3688.       Edit2.Text := CIPAddress;
  3689.       Panel3.Caption := '     IP Address:';
  3690.       Edit3.Text := CUserName;
  3691.       Panel5.Caption := '    User Name:';
  3692.       case PasswordControlVector of
  3693.         1 : Edit4.Text := CPassword;
  3694.         2 : Edit4.Text := '**********';
  3695.       end;
  3696.       Panel8.Caption := '      Password:';
  3697.       Edit5.Text := CStartDir;
  3698.       Panel9.Caption := '    Starting Dir:';
  3699.     end;
  3700.   end;
  3701. end;
  3702.  
  3703. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3704. procedure TCCINetCCForm.SetupNNTPSiteLists;
  3705. begin
  3706.   { Set up display for main form }
  3707.   CCINetCCForm.Tag := 4; { Usenet News Tag }
  3708.   CCINetCCForm.Caption := 'CC Internet Command Center -- Usenet News Mode';
  3709.   CCINetCCForm.ViewWinsockInfo1.Enabled := false;
  3710.   CCINetCCForm.FTP1.Enabled := true;
  3711.   CCINetCCForm.FTP2.Enabled := false;
  3712.   CCINetCCForm.UsenetNws1.Enabled := false;
  3713.   CCINetCCForm.News1.Enabled := true;
  3714.   CCINetCCForm.Label1.Caption := 'NNTP Server:';
  3715.   CCINetCCForm.Button1.Caption := 'Connect';
  3716.   CCINetCCForm.Label4.Caption := 'SubScribed Groups';
  3717.   CCINetCCForm.Label5.Caption := 'Unread Articles';
  3718.   { Create the working copy for use to make safe changes in info dlg }
  3719. end;
  3720.  
  3721. { This method saves off the Newsgroup and Article Lists }
  3722. procedure TCCINetCCForm.SaveNNTPNewsGroupLists;
  3723. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3724.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3725.     WorkingList : TList;
  3726.     Counter_1 ,
  3727.     Counter_2   : Integer;          { Loop counter              }
  3728.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3729.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3730. begin
  3731.   { Abort if no server to select }
  3732.   if ComboBox1.ItemIndex = -1 then exit;
  3733.   { Get number of server in list }
  3734.   WhichServer := ComboBox1.ItemIndex;
  3735.   { Set up the FTP sites list file name }
  3736.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3737.   { If the FTP Site List exists load it in }
  3738.   { set up the file and open it }
  3739.   AssignFile( TheNewsRCFile , NNTPNGLName );
  3740.   ReWrite( TheNewsRCFile );
  3741.   { read in the records }
  3742.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3743.   begin
  3744.     { Create the TCRecord }
  3745.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3746.     { Read in the data record }
  3747.     Seek( TheNewsRCFile , Counter_1 );
  3748.     Write( TheNewsRCFile , TheNGRecord^ );
  3749.     { Add the record to the list }
  3750.     WorkingList := TList( TheNGRecord^.GLTag );
  3751.     if WorkingList.Count > 0 then
  3752.     begin
  3753.       NNTPARName := TheNGRecord^.GFileName;
  3754.       TheNGArticlesList := TList.Create;
  3755.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3756.       ReWrite( TheNewsArticleFile );
  3757.       for Counter_2 := 0 to WorkingList.Count - 1 do
  3758.       begin
  3759.         TheNGARecord :=
  3760.          PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  3761.         Seek( TheNewsArticleFile , Counter_2 );
  3762.         Write( TheNewsArticleFile , TheNGARecord^ );
  3763.         Dispose( TheNGARecord );
  3764.       end;
  3765.       CloseFile( TheNewsArticleFile );
  3766.     end;
  3767.     WorkingList.Free;
  3768.     Dispose( TheNGRecord );
  3769.   end;
  3770.   { close the file }
  3771.   CloseFile( TheNewsRCFile );
  3772.   { Free the list itself }
  3773.   TheNewsRCList.Free;
  3774. end;
  3775.  
  3776. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3777. procedure TCCINetCCForm.SetupNNTPNewsGroupLists;
  3778. var TheNGRecord : PNewsGroupRecord; { Generic NGR Pointer       }
  3779.     TheNGARecord : PNewsGroupArticleRecord; {  }
  3780.     Counter_1 ,
  3781.     Counter_2   : Integer;          { Loop counter              }
  3782.     NNTPNGLName ,                   { NewsGroup Articles fname  }
  3783.     NNTPARName  : String;           { NNTP NewsRC filename      }
  3784. begin
  3785.   { Abort if no server to select }
  3786.   if ComboBox1.ItemIndex = -1 then exit;
  3787.   { Get number of server in list }
  3788.   WhichServer := ComboBox1.ItemIndex;
  3789.   { Create the sites list list }
  3790.   TheNewsRCList := TList.Create;
  3791.   { Set up the FTP sites list file name }
  3792.   NNTPNGLName := NewsPath + '\NEWSRC ' + IntToStr( WhichServer ) + '.NRC';
  3793.   { If the FTP Site List exists load it in }
  3794.   if FileExists( NNTPNGLName ) then
  3795.   begin
  3796.     { set up the file and open it }
  3797.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3798.     Reset( TheNewsRCFile );
  3799.     { read in the records }
  3800.     for Counter_1 := 0 to FileSize( TheNewsRCFile ) - 1 do
  3801.     begin
  3802.       { Create the TCRecord }
  3803.       New( TheNGRecord );
  3804.       { Read in the data record }
  3805.       Seek( TheNewsRCFile , Counter_1 );
  3806.       Read( TheNewsRCFile , TheNGRecord^ );
  3807.       { Add the record to the list }
  3808.       TheNewsRCList.Add( TheNGRecord );
  3809.     end;
  3810.     { close the file }
  3811.     CloseFile( TheNewsRCFile );
  3812.   end
  3813.   else
  3814.   { Otherwise create a default one with 3 delphi newsgroups }
  3815.   begin
  3816.     { create new record }
  3817.     New( TheNGRecord );
  3818.     { fill in its info }
  3819.     with TheNGRecord^ do
  3820.     begin
  3821.       GName                := 'Delphi Comps';
  3822.       GRealName            := 'comp.lang.pascal.delphi.components';
  3823.       GLowest              := 0;
  3824.       GHighest             := 0;
  3825.       GPostable            := true;
  3826.       GSubscribed          := true;
  3827.       GTotalArticles       := 0;
  3828.       GTotalAvailable      := 0;
  3829.       GLowestAvailable     := 0;
  3830.       GHighestAvailable    := 0;
  3831.       GTotalUnReadArticles := 0;
  3832.       GIDNumber            := 1;
  3833.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G1.NGR';
  3834.       GLTag                := 0;
  3835.     end;
  3836.     { add it to the list }
  3837.     TheNewsRCList.Add( TheNGRecord );
  3838.     { create new record }
  3839.     New( TheNGRecord );
  3840.     { fill in its info }
  3841.     with TheNGRecord^ do
  3842.     begin
  3843.       GName                := 'Delphi DB';
  3844.       GRealName            := 'comp.lang.pascal.delphi.databases';
  3845.       GLowest              := 0;
  3846.       GHighest             := 0;
  3847.       GPostable            := true;
  3848.       GSubscribed          := true;
  3849.       GTotalArticles       := 0;
  3850.       GTotalAvailable      := 0;
  3851.       GLowestAvailable     := 0;
  3852.       GHighestAvailable    := 0;
  3853.       GTotalUnReadArticles := 0;
  3854.       GIDNumber            := 2;
  3855.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G2.NGR';
  3856.       GLTag                := 0;
  3857.     end;
  3858.     { add it to the list }
  3859.     TheNewsRCList.Add( TheNGRecord );
  3860.     { create new record }
  3861.     New( TheNGRecord );
  3862.     { fill in its info }
  3863.     with TheNGRecord^ do
  3864.     begin
  3865.       GName                := 'Delphi Misc';
  3866.       GRealName            := 'comp.lang.pascal.delphi.misc';
  3867.       GLowest              := 0;
  3868.       GHighest             := 0;
  3869.       GPostable            := true;
  3870.       GSubscribed          := true;
  3871.       GTotalArticles       := 0;
  3872.       GTotalAvailable      := 0;
  3873.       GLowestAvailable     := 0;
  3874.       GHighestAvailable    := 0;
  3875.       GTotalUnReadArticles := 0;
  3876.       GIDNumber            := 3;
  3877.       GFileName            := 'NL' + IntToStr( WhichServer ) + 'G3.NGR';
  3878.       GLTag                := 0;
  3879.     end;
  3880.     { add it to the list }
  3881.     TheNewsRCList.Add( TheNGRecord );
  3882.     { create the file and write out the data, then close it }
  3883.     AssignFile( TheNewsRCFile , NNTPNGLName );
  3884.     Rewrite( TheNewsRCFile );
  3885.     for Counter_1 := 0 to 2 do
  3886.     begin
  3887.       TheNGRecord :=
  3888.        PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3889.       Seek( TheNewsRCFile , Counter_1 );
  3890.       Write( TheNewsRCFile , TheNGRecord^ );
  3891.     end;
  3892.     CloseFile( TheNewsRCFile );
  3893.   end;
  3894.   { Load in Articles Records and create storage lists }
  3895.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3896.   begin
  3897.     NNTPARName := PNewsGroupRecord(
  3898.      TheNewsRCList.Items[ Counter_1 ] )^.GFileName;
  3899.     if FileExists( NewsPath + '\' + NNTPARName ) then
  3900.     begin
  3901.       TheNGArticlesList := TList.Create;
  3902.       AssignFile( TheNewsArticleFile , NewsPath + '\' + NNTPARName );
  3903.       Reset( TheNewsArticleFile );
  3904.       for Counter_2 := 0 to FileSize( TheNewsArticleFile ) - 1 do
  3905.       begin
  3906.         New( TheNGARecord );
  3907.         Seek( TheNewsArticleFile , Counter_2 );
  3908.         Read( TheNewsArticleFile , TheNGARecord^ );
  3909.         TheNGArticlesList.Add( TheNGARecord );
  3910.       end;
  3911.       CloseFile( TheNewsArticleFile );
  3912.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3913.        Longint( TheNGArticlesList );
  3914.     end
  3915.     else
  3916.     begin
  3917.       TheNGArticlesList := TList.Create;
  3918.       PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^.GLTag :=
  3919.        Longint( TheNGArticlesList );
  3920.     end;
  3921.   end;
  3922.   { Create working Newsgroup list for later }
  3923.   TheWorkingNRCSL := TList.Create;
  3924.   For Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3925.   begin
  3926.     New( TheNGRecord );
  3927.     TheNGRecord^ := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] )^;
  3928.     TheWorkingNRCSL.Add( TheNGRecord );
  3929.   end;
  3930. end;
  3931.  
  3932. { This procedure populates LB2 with article subjects for any }
  3933. { available articles for a given newsgroup.                  }
  3934. procedure TCCINetCCForm.PopulateLB2WithArticleHeaders;
  3935. var Counter_1    : Integer;
  3936.     TheNGARecord : PNewsGroupArticleRecord;
  3937.     TempString   : String;
  3938. begin
  3939.   { Clear target list box }
  3940.   ListBox2.Clear;
  3941.   for Counter_1 := 0 to TheNGArticlesList.Count - 1 do
  3942.   begin
  3943.     TheNGARecord :=
  3944.      PNewsGroupArticleRecord( TheNGArticlesList.Items[ Counter_1 ] );
  3945.     TempString := '    [' + IntToStr( Counter_1 ) + '] ' +
  3946.      TheNGARecord^.NGASubject;
  3947.     if TheNGARecord^.NGADownloaded then TempString[ 1 ] :=
  3948.      'D';
  3949.     if TheNGARecord^.NGARead then TempString[ 3 ] := 'R';
  3950.     if TheNGARecord^.NGAPosted then TempString[ 3 ] := 'S';
  3951.     ListBox2.Items.Add( TempString );
  3952.   end;
  3953. end;
  3954.  
  3955. { This procedure swaps in the list of subscribed newsgroups to LB1 }
  3956. { and calls another procedure to populate LB2 with any available   }
  3957. { articles for the newsgroup.                                      }
  3958. procedure TCCINetCCForm.SetupNewsGroupListboxes;
  3959. var Counter_1   : Integer;
  3960.     TempString  : String;
  3961.     TheNGRecord : PNewsGroupRecord;
  3962. begin
  3963.   ListBox1.Clear;
  3964.   ListBox1.Tag := 5;
  3965.   ListBox2.Tag := 5;
  3966.   Label4.Caption := 'NewsGroups';
  3967.   Label5.Caption := 'Articles';
  3968.   if TheNewsRCList.Count = 0 then
  3969.   begin
  3970.     ListBox2.Clear;
  3971.     exit;
  3972.   end;
  3973.   ComboBox1.Clear;
  3974.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  3975.   begin
  3976.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  3977.     TempString := TheNGRecord^.GName;
  3978.     ComboBox1.Items.Add( TheNGRecord^.GRealName );
  3979.     if TheNGRecord^.GSubscribed then
  3980.      TempString := '[S] ' + TempString else TempString := '[U] ' + TempString;
  3981.     TempString := TempString + '{' + IntToStr( TheNGRecord^.GTotalNew ) + '}';
  3982.     ListBox1.Items.Add( TempString );
  3983.   end;
  3984.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ 0 ] );
  3985.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  3986.   PopulateLB2WithArticleHeaders;
  3987.   Label1.Caption := 'NewsGroup:';
  3988.   ComboBox1.ItemIndex := 0;
  3989.   Button1.Caption := 'DL Article(s)';
  3990.   Tag := 5; { Set download vector }
  3991. end;
  3992.  
  3993. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  3994. procedure TCCINetCCForm.SetupNNTPServersInfoDisplay;
  3995. var Counter_1  : Integer;            { Loop counter        }
  3996. begin
  3997.   { Set tag for NNTP stuff }
  3998.   CCICInfoDlg.Tag := 4; { Usenet News Tag -- servers }
  3999.   { set up caption of main label }
  4000.   CCICInfoDlg.Label2.Caption := 'News Server Sites';
  4001.   { hide outline panel }
  4002.   CCICInfoDlg.Panel6.Visible := false;
  4003.   CCICInfoDlg.Panel5.Visible := false;
  4004.   CCICInfoDlg.Panel8.Visible := false;
  4005.   CCICInfoDlg.Panel9.Visible := false;
  4006.   { clear the list box }
  4007.   CCICInfoDlg.ListBox2.Clear;
  4008.   CCINetCCForm.ComboBox1.Clear;
  4009.   { add profile strings to the list box }
  4010.   for Counter_1 := 0 to TheNewsServerList.Count - 1 do
  4011.   begin
  4012.     CCICInfoDlg.ListBox2.Items.Add( PConnectionsRecord(
  4013.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  4014.     CCINetCCForm.ComboBox1.Items.Add( PConnectionsRecord(
  4015.      TheNewsServerList.Items[ Counter_1 ] )^.CProfile );
  4016.   end;
  4017.   { Set up caption of special button }
  4018.   CCICInfoDlg.Button1.Visible := false;
  4019.   { Start with top record }
  4020.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  4021.   CCINetCCForm.ComboBox1.ItemIndex := 0;
  4022.   { put in data from top record and reset captions }
  4023.   with PConnectionsRecord( TheNewsServerList.Items[ 0 ] )^ do
  4024.   begin
  4025.     with CCICInfoDlg do
  4026.     begin
  4027.       Edit1.Text := CProfile;
  4028.       Panel2.Caption := '            Name:';
  4029.       Edit2.Text := CIPAddress;
  4030.       Panel3.Caption := '     IP Address:';
  4031.     end;
  4032.   end;
  4033. end;
  4034.  
  4035. { This procedure switches in the FTP sites list to the info dlg and main cbox }
  4036. procedure TCCINetCCForm.SetupNNTPNewsGroupsInfoDisplay;
  4037. var Counter_1  : Integer;            { Loop counter        }
  4038.     WorkingFileName : String;
  4039.     TheWorkingSL : TStringList;
  4040. begin
  4041.   { Set tag for NNTP stuff }
  4042.   CCICInfoDlg.Tag := 5; { Usenet News Tag -- newsgroups }
  4043.   { set up caption of main label }
  4044.   CCICInfoDlg.Label2.Caption := 'Active NewsGroups';
  4045.   { hide outline panel }
  4046.   CCICInfoDlg.Panel5.Visible := true;
  4047.   CCICInfoDlg.Panel6.Visible := true;
  4048.   CCICInfoDlg.Panel6.Height := 224;
  4049.   CCICInfoDlg.Panel6.Top := 120;
  4050.   CCICInfoDlg.Label1.Caption := 'Available NewsGroups';
  4051.   CCICInfoDlg.Panel8.Visible := false;
  4052.   CCICInfoDlg.Panel9.Visible := false;
  4053.   { clear the list box }
  4054.   CCICInfoDlg.ListBox2.Clear;
  4055.   { add profile strings to the list box }
  4056.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  4057.   begin
  4058.     CCICInfoDlg.ListBox2.Items.Add( PNewsGroupRecord(
  4059.      TheNewsRCList.Items[ Counter_1 ] )^.GName );
  4060.   end;
  4061.   { Set up caption of special button }
  4062.   CCICInfoDlg.Button1.Visible := true;
  4063.   CCICInfoDlg.Button1.Caption := 'Toggle Subscription';
  4064.   { Start with top record }
  4065.   CCICInfoDlg.ListBox2.ItemIndex := 0;
  4066.   { put in data from top record and reset captions }
  4067.   with PNewsGroupRecord( TheNewsRCList.Items[ 0 ] )^ do
  4068.   begin
  4069.     with CCICInfoDlg do
  4070.     begin
  4071.       Edit1.Text := GName;
  4072.       Panel2.Caption := 'NG Name:';
  4073.       Edit2.Text := GRealName;
  4074.       Panel3.Caption := 'NG Real Name:';
  4075.       if GSubscribed then
  4076.       Edit3.Text := 'Subscribed' else Edit3.Text := 'UnSubscribed';
  4077.       Panel5.Caption := 'Status:';
  4078.     end;
  4079.   end;
  4080.   if newsgroupListloaded then exit;
  4081.   WorkingFileName := NewsPath + '\NEWSGRP.TXT';
  4082.   if FileExists( WorkingFileName ) then
  4083.   begin
  4084.     if MessageDlg( 'Load News Groups File? (Long operation...)',
  4085.      mtConfirmation,mbYesNoCancel,0) = mrYes then
  4086.     begin
  4087.       CCICInfoDlg.ListBox1.Clear;
  4088.       TheWorkingSL := TStringList.Create;
  4089.       try
  4090.         TheWorkingSL.LoadFromFile( WorkingFileName );
  4091.         CCICInfoDlg.ListBox1.Items.Assign( TheWorkingSL );
  4092.       except
  4093.         MessageDlg( 'News Group List Too Large! Use WordPad/Write to view ' +
  4094.                       NewsPath + '\NEWGRP.TXT' , mtInformation,[mbOK],0);
  4095.         TheWorkingSL.Free;
  4096.         NewsgroupListLoaded := false;
  4097.         exit;
  4098.       end;
  4099.       TheWorkingSL.Free;
  4100.       NewsgroupListLoaded := true;
  4101.     end;
  4102.   end;
  4103. end;
  4104.  
  4105. { This procedure scans a line of UNIX-style text for #10's and }
  4106. { outputs them as lines to the memo. It stops at #0.           }
  4107. procedure TCCINetCCForm.AddNullTermTextToMemo( TheTextToAdd   : String;
  4108.                                  TheMemoToAddTo : TMemo   );
  4109. var
  4110.   TextLength ,            { Total chars to output         }
  4111.   Counter_1    : integer; { Loop Index                    }
  4112. begin
  4113.   { Make the target memo visible just in case }
  4114.   TheMemoToAddTo.Visible := true;
  4115.   { Find total chars to output }
  4116.   TextLength := Length( TheTextToAdd );
  4117.   { If none then leave }
  4118.   if TextLength = 0 then exit;
  4119.   { Loop along the string }
  4120.   for Counter_1 := 1 to TextLength do
  4121.   begin
  4122.     { If hit ASCII 10 then assume end of line and output }
  4123.     if TheTextToAdd[ Counter_1 ] = #10 then
  4124.     begin
  4125.       { Use a try loop incase memo fills up }
  4126.       try
  4127.         { Add the line }
  4128.         TheMemoToAddTo.Lines.Add( TheLine );
  4129.       except
  4130.         { If memo fills up }
  4131.         on EOutOfResources do
  4132.         begin
  4133.           { Clear the old data }
  4134.           TheMemoToAddTo.Clear;
  4135.           { Output the new }
  4136.           TheMemoToAddTo.Lines.Add( TheLine );
  4137.         end;
  4138.       end;
  4139.       { clear the output buffer }
  4140.       TheLine := '';
  4141.     end
  4142.     else
  4143.     { Otherwise look for null terminator from Winsock }
  4144.     begin
  4145.       { If don't hit null terminator then add the char to op buffer }
  4146.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4147.       begin
  4148.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4149.       end
  4150.       else break; { Otherwise drop out of the loop }
  4151.     end;
  4152.   end;
  4153. end;
  4154.  
  4155. { This function scans a line of UNIX-style text for #10's and }
  4156. { outputs the first line as its return value,stopping at #0.  }
  4157. function TCCINetCCForm.AddNullTermTextToLabel( TheTextToAdd   : String ) : String;
  4158. var
  4159.   TheLine      : String;  { Buffer to output current line }
  4160.   TextLength ,            { Total chars to output         }
  4161.   Counter_1    : integer; { Loop Index                    }
  4162. begin
  4163.   { Clear output buffer }
  4164.   TheLine := '';
  4165.   { Find total chars to output }
  4166.   TextLength := Length( TheTextToAdd );
  4167.   { If none then leave }
  4168.   if TextLength = 0 then
  4169.   begin
  4170.     { Return nothing }
  4171.     Result := '';
  4172.     { Leave }
  4173.     exit;
  4174.   end;
  4175.   { Loop along the string }
  4176.   for Counter_1 := 1 to TextLength do
  4177.   begin
  4178.     { If hit ASCII 10 then assume end of line and output }
  4179.     if TheTextToAdd[ Counter_1 ] = #10 then
  4180.     begin
  4181.       { Return first line }
  4182.       Result := TheLine;
  4183.       { Leave }
  4184.       exit;
  4185.     end
  4186.     else
  4187.     { Otherwise look for null terminator from Winsock }
  4188.     begin
  4189.       { If don't hit null terminator then add the char to op buffer }
  4190.       if TheTextToAdd[ Counter_1 ] <> #0 then
  4191.       begin
  4192.         TheLine := TheLine + TheTextToAdd[ Counter_1 ];
  4193.       end
  4194.       else break; { Otherwise drop out of the loop }
  4195.     end;
  4196.   end;
  4197.   { If hit #0 before #10 return buffer }
  4198.   Result := TheLine;
  4199. end;
  4200.  
  4201. { Show busy cursors }
  4202. procedure TCCINetCCForm.SetHGCursors;
  4203. begin
  4204.   CCInetCCForm.Cursor := crHourGlass;
  4205.   CCInetCCForm.Memo1.Cursor := crHourGlass;
  4206. end;
  4207.  
  4208. { Show normal cursors }
  4209. procedure TCCINetCCForm.SetNormalCursors;
  4210. begin
  4211.   CCInetCCForm.Cursor := crDefault;
  4212.   CCInetCCForm.Memo1.Cursor := crDefault;
  4213. end;
  4214.  
  4215. { Exit method }
  4216. procedure TCCINetCCForm.Exit1Click(Sender: TObject);
  4217. begin
  4218.   Close;
  4219. end;
  4220.  
  4221. { This method adds a line to the progress text stringlist  }
  4222. { If an exception occurs, the list is full, and it is auto }
  4223. { saved to the progress text file name, then cleared.      }
  4224. procedure TCCINetCCForm.AddProgressText( WhatText : String );
  4225. begin
  4226.   { Use a try..except loop to catch list overflows }
  4227.   try
  4228.     { Try the normal add }
  4229.     ProgressList.Add( WhatText );
  4230.   except
  4231.     { Any list error is assumed to be a list overflow }
  4232.     on EListError do
  4233.     begin
  4234.       { Save the list to the preset file name }
  4235.       ProgressList.SaveToFile( ProgressFileName );
  4236.       { Clear the list to make more room }
  4237.       ProgressList.Clear;
  4238.       { And redo the add; any further errors will except normally }
  4239.       ProgressList.Add( WhatText );
  4240.     end;
  4241.     { This might happen too! }
  4242.     on EOutOfResources do
  4243.     begin
  4244.       { Save the list to the preset file name }
  4245.       ProgressList.SaveToFile( ProgressFileName );
  4246.       { Clear the list to make more room }
  4247.       ProgressList.Clear;
  4248.       { And redo the add; any further errors will except normally }
  4249.       ProgressList.Add( WhatText );
  4250.     end;
  4251.   end;
  4252. end;
  4253.  
  4254. { This method either adds the progress line to the current memo }
  4255. { or puts it in the status caption at normal colors.            }
  4256. procedure TCCINetCCForm.ShowProgressText( WhatText : String );
  4257. begin
  4258.   { Use the POV to determine where to show progress info }
  4259.   case ProgressOutputVector of
  4260.     POV_MEMO : begin { Output into the memo  }
  4261.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4262.                end;
  4263.     POV_STAT : begin { Output on status line }
  4264.                  { Set panel caption font to black }
  4265.                  Panel1.Font.Color := clBlack;
  4266.                  { Get the first line of text and put in caption }
  4267.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4268.                end;
  4269.   end;
  4270. end;
  4271.  
  4272. { This method is identical with SPT except sets status color to red and beeps }
  4273. procedure TCCINetCCForm.ShowProgressErrorText( WhatText : String );
  4274. begin
  4275.   { Do error beep }
  4276.   MessageBeep( mb_IconExclamation );
  4277.   { Use the POV to determine where to show progress info }
  4278.   case ProgressOutputVector of
  4279.     POV_MEMO : begin { Output into the memo  }
  4280.                  AddNullTermTextToMemo( WhatText , Memo1 );
  4281.                end;
  4282.     POV_STAT : begin { Output on status line }
  4283.                  { Set panel caption font to black }
  4284.                  Panel1.Font.Color := clRed;
  4285.                  { Get the first line of text and put in caption }
  4286.                  Panel1.Caption := AddNullTermTextToLabel( WhatText );
  4287.                end;
  4288.   end;
  4289. end;
  4290.  
  4291. { This is the boilerplate method used to handle Socket errors gracefully }
  4292. procedure TCCINetCCForm.SocketsErrorOccurred( Sender     : TObject;
  4293.                                               ErrorCode  : Integer;
  4294.                                               TheMessage : String   );
  4295. begin
  4296.   { Set the global error code flag }
  4297.   GlobalErrorCode := ErrorCode;
  4298.   { If a timeout error }
  4299.   if ErrorCode = WSAETIMEDOUT then
  4300.   begin
  4301.     { Set the aborted flag }
  4302.     GlobalAbortedFlag := True;
  4303.     { But clear the error code for graceful handling }
  4304.     GlobalErrorCode := 0;
  4305.   end
  4306.   else
  4307.   begin
  4308.     { Otherwise set the progress buffer to the error message }
  4309.     AddProgressText( TheMessage );
  4310.     { And show the progress text as set by option }
  4311.     ShowProgressErrorText( TheMessage );
  4312.   end;
  4313. end;
  4314.  
  4315. procedure TCCINetCCForm.FormCreate(Sender: TObject);
  4316. begin
  4317.   { Create the progress string list }
  4318.   ProgressList := TStringList.Create;
  4319.   { Create the file name for saving the progress list }
  4320.   ProgressFileName := ExpandFileName( 'PROGRESS.TXT' );
  4321.   { Default progress output to status line }
  4322.   ProgressOutputVector := POV_STAT;
  4323.   { Set password control stuff }
  4324.   PasswordControlVector := 2;
  4325.   CurrentPasswordString := 'guest@nowhere.com';
  4326.   CurrentRealPWString := 'guest@nowhere.com';
  4327.   NewMessageInProgress := false;
  4328.   EmailLoaded := false;
  4329.   NewsGroupListLoaded := false;
  4330.   { Get Ini file Data }
  4331.   ReadIniData;
  4332.   LoadFTPSiteFile;
  4333.   LoadNNTPSiteFile;
  4334.   LoadEMailServerFile;
  4335.   TheFTPComponent := TFTPComponent.Create( CCInetCCForm );
  4336.   TheFTPComponent.Parent := CCInetCCForm;
  4337.   TheNNTPComponent := TNNTPComponent.Create( CCInetCCForm );
  4338.   TheNNTPComponent.Parent := CCInetCCForm;
  4339.   ThePOP3SMTPComponent := TPOP3SMTPComponent.Create( CCInetCCForm );
  4340.   ThePOP3SMTPComponent.Parent := CCInetCCForm;
  4341.   TheUUObject := TUUCodingObject.Create( Self );
  4342.   TheUUObject.Parent := self;
  4343.   TheMIMEObject := TMIMECodingObject.Create( Self );
  4344.   TheMIMEObject.Parent := self;
  4345. end;
  4346.  
  4347. procedure TCCINetCCForm.FormDestroy(Sender: TObject);
  4348. begin
  4349.   { Free the progress text stringlist if assigned }
  4350.   if assigned( ProgressList ) then ProgressList.Free;
  4351.   { Save off the Ini data }
  4352.   WriteIniData;
  4353.   { Save and remove FTP site list stuff }
  4354.   SaveFTPSiteFile;
  4355.   SaveNNTPSiteFile;
  4356.   SaveEmailServerFile;
  4357.   if Assigned( TheFTPComponent ) then TheFTPComponent.Free;
  4358.   if Assigned( TheNNTPComponent ) then TheNNTPComponent.Free;
  4359.   if Assigned( ThePOP3SMTPComponent ) then ThePOP3SMTPComponent.Free;
  4360.   if Assigned( TheUUObject ) then TheUUObject.Free;
  4361.   if Assigned( TheMIMEObject ) then TheMIMEObject.Free;
  4362. end;
  4363.  
  4364. procedure TCCINetCCForm.Description1Click(Sender: TObject);
  4365. var
  4366.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4367.   TheData    : String;    { Holder for data                           }
  4368. begin
  4369.   { Create socket; auto calls WSAStartup }
  4370.   TempSocket := TCCSocket.Create( Self );
  4371.   { Do parent just for kicks; no longer needed }
  4372.   TempSocket.Parent := self;
  4373.   { Put in error handler }
  4374.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4375.   TheData := StrPas( TempSocket.Socket_WSA_Data.Description_String );
  4376.   { Display the Description String }
  4377.   AddProgressText( TheData );
  4378.   { And show the progress text as set by option }
  4379.   ShowProgressText( TheData );
  4380.   { Free the socket; auto calls WSACleanup }
  4381.   TempSocket.Free;
  4382. end;
  4383.  
  4384. procedure TCCINetCCForm.SystemStatus1Click(Sender: TObject);
  4385. var
  4386.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4387.   TheData    : String;    { Holder for data                           }
  4388. begin
  4389.   { Create socket; auto calls WSAStartup }
  4390.   TempSocket := TCCSocket.Create( Self );
  4391.   { Do parent just for kicks; no longer needed }
  4392.   TempSocket.Parent := self;
  4393.   { Put in error handler }
  4394.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4395.   TheData := StrPas( TempSocket.Socket_WSA_Data.System_Status_String );
  4396.   { Display the Description String }
  4397.   AddProgressText( TheData );
  4398.   { And show the progress text as set by option }
  4399.   ShowProgressText( TheData );
  4400.   { Free the socket; auto calls WSACleanup }
  4401.   TempSocket.Free;
  4402. end;
  4403.  
  4404. procedure TCCINetCCForm.VendorSpecific1Click(Sender: TObject);
  4405. var
  4406.   TempSocket : TCCSocket; { Temporary socket just to get Winsock info }
  4407.   TheData    : String;    { Holder for data                           }
  4408. begin
  4409.   { Create socket; auto calls WSAStartup }
  4410.   TempSocket := TCCSocket.Create( Self );
  4411.   { Do parent just for kicks; no longer needed }
  4412.   TempSocket.Parent := self;
  4413.   { Put in error handler }
  4414.   TempSocket.OnErrorOccurred := SocketsErrorOccurred;
  4415.   TheData := StrPas( TempSocket.Socket_WSA_Data.Vendor_Specific_String );
  4416.   { Display the Description String }
  4417.   AddProgressText( TheData );
  4418.   { And show the progress text as set by option }
  4419.   ShowProgressText( TheData );
  4420.   { Free the socket; auto calls WSACleanup }
  4421.   TempSocket.Free;
  4422. end;
  4423.  
  4424. { This method sets the progress output vector to the memo }
  4425. procedure TCCINetCCForm.ViewInEditWindow1Click(Sender: TObject);
  4426. begin
  4427.   { Set the vector }
  4428.   ProgressOutputVector := POV_MEMO;
  4429.   { Keep the menu options consistent }
  4430.   ViewInEditWindow1.Checked := true;
  4431.   ViewInStatusLine1.Checked := false;
  4432. end;
  4433.  
  4434. { This method sets the progress output vector to the status line }
  4435. procedure TCCINetCCForm.ViewInStatusLine1Click(Sender: TObject);
  4436. begin
  4437.   { Set the vector }
  4438.   ProgressOutputVector := POV_STAT;
  4439.   { Keep the menus consistent }
  4440.   ViewInEditWindow1.Checked := false;
  4441.   ViewInStatusLine1.Checked := true;
  4442. end;
  4443.  
  4444. procedure TCCINetCCForm.SaveToFile1Click(Sender: TObject);
  4445. begin
  4446.   { Set up the dialog parameters }
  4447.   OpenDialog1.Filename := ProgressFileName;
  4448.   OpenDialog1.Title := 'Select Filename for Progress File';
  4449.   OpenDialog1.Filter := 'Text Files|*.txt';
  4450.   { If the dialog is not cancelled then save and clear }
  4451.   if OpenDialog1.Execute then
  4452.   begin
  4453.     ProgressFileName := OpenDialog1.FileName;
  4454.     ProgressList.SaveToFile( ProgressFileName );
  4455.     ProgressList.Clear;
  4456.   end;
  4457. end;
  4458.  
  4459. procedure TCCINetCCForm.IPAddress1Click(Sender: TObject);
  4460. begin
  4461.   { Set up info dialog for IP Address getting }
  4462.   CCICInfoDlg.Caption := 'CC Internet Center -- Translate IP Address';
  4463.   CCICInfoDlg.Panel4.Visible := false;
  4464.   CCICInfoDlg.Panel6.Visible := false;
  4465.   CCICInfoDlg.Panel9.Visible := false;
  4466.   CCICInfoDlg.Panel8.Visible := false;
  4467.   CCICInfoDlg.BitBtn2.Visible := false;
  4468.   CCICInfoDlg.Button1.Caption := 'Get IP Address';
  4469.   CCICInfoDlg.Button2.Visible := false;
  4470.   CCICInfoDlg.Button3.Visible := false;
  4471.   CCICInfoDlg.Button4.Visible := false;
  4472.   CCICInfoDlg.Panel2.Caption := 'IP Addr Name:';
  4473.   CCICInfoDlg.Panel3.Caption := '    Dotted Dec:';
  4474.   CCICInfoDlg.Panel5.Caption := '           Binary:';
  4475.   CCICInfoDlg.Edit1.Text := '';
  4476.   CCICInfoDlg.Edit2.Text := '';
  4477.   CCICInfoDlg.Edit3.Text := '';
  4478.   { Set IP Address Mode }
  4479.   CCICInfoDlg.Tag := 1;
  4480.   { Show Modally to get the information }
  4481.   CCICInfoDlg.ShowModal;
  4482.   { Reset the info dialog to default conditions }
  4483.   CCICInfoDlg.Caption := 'CC Internet Command Center Information Dialog';
  4484.   CCICInfoDlg.Panel4.Visible := true;
  4485.   CCICInfoDlg.Panel6.Visible := true;
  4486.   CCICInfoDlg.Panel9.Visible := true;
  4487.   CCICInfoDlg.Panel8.Visible := true;
  4488.   CCICInfoDlg.BitBtn2.Visible := true;
  4489.   CCICInfoDlg.Button1.Caption := 'Anonymous Login';
  4490.   CCICInfoDlg.Button2.Visible := true;
  4491.   CCICInfoDlg.Button3.Visible := true;
  4492.   CCICInfoDlg.Button4.Visible := true;
  4493.   CCICInfoDlg.Panel2.Caption := '             Name:';
  4494.   CCICInfoDlg.Panel3.Caption := '    IP Address:';
  4495.   CCICInfoDlg.Panel5.Caption := ' User Name:';
  4496.   CCICInfoDlg.Edit1.Text := '';
  4497.   CCICInfoDlg.Edit2.Text := '';
  4498.   CCICInfoDlg.Edit3.Text := '';
  4499. end;
  4500.  
  4501. procedure TCCINetCCForm.FTP1Click(Sender: TObject);
  4502. begin
  4503.   { Set up the FTP Data displays }
  4504.   SetupFTPSiteLists;
  4505.   ListBox1.Clear;
  4506.   ListBox2.Clear;
  4507. end;
  4508.  
  4509. procedure TCCINetCCForm.FormResize(Sender: TObject);
  4510. begin
  4511.   { Use tag vector to determine what to do }
  4512.   case Tag of
  4513.     { if FTP , make sure two list boxes are same height }
  4514.     2 : begin
  4515.           Panel6.Height := (( Panel4.Height div 2 ) - 30 );
  4516.           Panel4.Width := 185;
  4517.         end;
  4518.     4 : begin
  4519.           Panel6.Height := 118;
  4520.           Panel4.Width := 250;
  4521.         end;
  4522.   end;
  4523. end;
  4524.  
  4525. procedure TCCINetCCForm.FTPSites1Click(Sender: TObject);
  4526. begin
  4527.   { Show Modally to get the information }
  4528.   CCICInfoDlg.ShowModal;
  4529. end;
  4530.  
  4531. procedure TCCINetCCForm.FTP3Click(Sender: TObject);
  4532. begin
  4533.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 1;
  4534.   CCICPrefsDlg.Tag := 2;
  4535.   CCICPrefsDlg.ShowModal;
  4536. end;
  4537.  
  4538. procedure TCCINetCCForm.ConnectToSite1Click(Sender: TObject);
  4539. var Counter_1 : Integer;
  4540. begin
  4541.   if Lowercase( PConnectionsRecord( TheFTPSiteList.Items[
  4542.    ComboBox1.ItemIndex ] )^.CUserName ) = 'anonymous' then
  4543.   begin
  4544.     for Counter_1 := 1 to TheAnonRedialVector do
  4545.     begin
  4546.       DoFTPConnection( PConnectionsRecord(
  4547.          TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4548.       if TheFTPComponent.Connection_Established then exit;
  4549.     end;
  4550.   end
  4551.   else DoFTPConnection( PConnectionsRecord(
  4552.    TheFTPSiteList.Items[ ComboBox1.ItemIndex ] ));
  4553. end;
  4554.  
  4555. procedure TCCINetCCForm.Button1Click(Sender: TObject);
  4556. begin
  4557.   case Tag of
  4558.     2 : begin
  4559.           if not TheFTPComponent.Connection_Established then
  4560.            ConnectToSite1Click( Self ) else
  4561.            begin
  4562.              DoFTPDisconnect;
  4563.              TheFTPComponent.Connection_Established := false;
  4564.              DisableFTPMenus;
  4565.            end;
  4566.         end;
  4567.     4 : begin
  4568.           ConnectAndUpdate1Click( Self );
  4569.         end;
  4570.     5 : begin
  4571.           GetMarked1Click( Self );
  4572.         end;
  4573.     6 : begin
  4574.            CheckMail1Click( Self );
  4575.         end;
  4576.   end;
  4577. end;
  4578.  
  4579. procedure TCCINetCCForm.ViewasText1Click(Sender: TObject);
  4580. begin
  4581.   { Assume valid FTP component and have it send its text into the progress text}
  4582.   TheFTPComponent.GetRemoteDirectoryListingToMemo;
  4583. end;
  4584.  
  4585. procedure TCCINetCCForm.Disconnect1Click(Sender: TObject);
  4586. begin
  4587.   DoFTPDisconnect;
  4588.   DisableFTPMenus;
  4589. end;
  4590.  
  4591. procedure TCCINetCCForm.EnableFTPMenus;
  4592. begin
  4593.   Button1.Caption := 'Disconnect';
  4594.   ConnectToSite1.Enabled := false;
  4595.   Disconnect1.Enabled := true;
  4596.   Directory1.Enabled := true;
  4597.   UploadMarked1.Enabled := true;
  4598.   DownloadMarked1.Enabled := true;
  4599. end;
  4600.  
  4601. procedure TCCINetCCForm.DisableFTPMenus;
  4602. begin
  4603.   Button1.Caption := 'Connect';
  4604.   ConnectToSite1.Enabled := true;
  4605.   Disconnect1.Enabled := false;
  4606.   Directory1.Enabled := false;
  4607.   UploadMarked1.Enabled := false;
  4608.   DownloadMarked1.Enabled := false;
  4609.   FTP1.Enabled := true;
  4610.   UseNetNws1.Enabled := true;
  4611.   IPAddress1.Enabled := true;
  4612.   FTP2.Enabled := false;
  4613. end;
  4614.  
  4615. procedure TCCINetCCForm.EnableNNTPMenus;
  4616. begin
  4617.   Button1.Caption := 'Disconnect';
  4618.   ConnectAndUpdate1.Enabled := false;
  4619.   Disconnect2.Enabled := true;
  4620.   CheckNewNews1.Enabled := true;
  4621.   GetMarked1.Enabled := true;
  4622.   Article1.Enabled := true;
  4623.   Post1.Enabled := true;
  4624.   SubScribedNewsgroups1.Enabled := true;
  4625.   Trash1.Enabled := true;
  4626.   Headers1.Enabled := true;
  4627.   DownLoadActiveNewsGroups1.Enabled := true;
  4628. end;
  4629.  
  4630. procedure TCCINetCCForm.DisableNNTPMenus;
  4631. begin
  4632.   Button1.Caption := 'Connect';
  4633.   ConnectAndUpdate1.Enabled := True;
  4634.   Disconnect2.Enabled := false;
  4635.   CheckNewNews1.Enabled := false;
  4636.   GetMarked1.Enabled := false;
  4637.   Article1.Enabled := false;
  4638.   Post1.Enabled := false;
  4639.   SubScribedNewsgroups1.Enabled := false;
  4640.   Trash1.Enabled := false;
  4641.   Headers1.Enabled := false;
  4642.   DownLoadActiveNewsGroups1.Enabled := false;
  4643. end;
  4644.  
  4645. procedure TCCINetCCForm.ToDisplay1Click(Sender: TObject);
  4646. var Counter_1 : Integer;
  4647. begin
  4648.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4649.   begin
  4650.     if Listbox1.Selected[ Counter_1 ] then
  4651.     begin
  4652.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4653.       TheFTPComponent.
  4654.        ReceiveASCIIRemoteFileToMemo( Listbox1.Items[ Counter_1 ] );
  4655.     end;
  4656.   end;
  4657. end;
  4658.  
  4659. procedure TCCINetCCForm.ToFile1Click(Sender: TObject);
  4660. var Counter_1 : Integer;
  4661.     W16Name   : String;
  4662. begin
  4663.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4664.   begin
  4665.     if Listbox1.Selected[ Counter_1 ] then
  4666.     begin
  4667.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4668.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4669.       TheFTPComponent.
  4670.        ReceiveASCIIRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4671.     end;
  4672.   end;
  4673. end;
  4674.  
  4675. procedure TCCINetCCForm.Binary2Click(Sender: TObject);
  4676. var Counter_1 : Integer;
  4677.     W16Name   : String;
  4678. begin
  4679.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4680.   begin
  4681.     if Listbox1.Selected[ Counter_1 ] then
  4682.     begin
  4683.       FileNameToXFer := ListBox1.Items[ Counter_1 ];
  4684.       W16Name := TheFTPComponent.GetWin16Filename( FileNameToXFer );
  4685.       TheFTPComponent.
  4686.        ReceiveBinaryRemoteFile( Listbox1.Items[ Counter_1 ] , W16Name );
  4687.     end;
  4688.   end;
  4689. end;
  4690.  
  4691. procedure TCCINetCCForm.Change1Click(Sender: TObject);
  4692. var TheDir : String;
  4693. begin
  4694.   if ListBox1.ItemIndex = -1 then exit;
  4695.   TheDir := ListBox1.Items[ ListBox1.ItemIndex ];
  4696.   if TheFTPComponent.SetRemoteDirectory( TheDir ) then
  4697.   begin
  4698.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir ); 
  4699.     { Put up remote directory via PWD and strip quotes }
  4700.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4701.     { Get the listings of directories and exit OK }
  4702.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4703.   end;
  4704. end;
  4705.  
  4706. procedure TCCINetCCForm.ChangeLocal1Click(Sender: TObject);
  4707. var TheDir : String;
  4708. begin
  4709.   if ListBox2.ItemIndex = -1 then exit;
  4710.   TheDir := ListBox2.Items[ ListBox2.ItemIndex ];
  4711.   TheDir := TheFTPComponent.StripBrackets( TheDir );
  4712.   if TheDir = '..' then
  4713.   begin
  4714.     ChDir( TheDir );
  4715.   end
  4716.   else
  4717.   begin
  4718.     TheDir := ExpandFileName( TheDir );
  4719.     ChDir( TheDir );
  4720.   end;
  4721.   TheFTPComponent.GetLocalDirectoryAndListing( TheDir , Listbox2 );
  4722.   if Label5.Canvas.TextWidth( TheDir ) > Label5.Width then
  4723.    TheDir := TheFTPComponent.GetShortPathName( TheDir );
  4724.   Label5.Caption := TheDir;
  4725. end;
  4726.  
  4727. procedure TCCINetCCForm.ListBox1DblClick(Sender: TObject);
  4728. begin
  4729.   case Tag of
  4730.     2 : begin
  4731.           case DefaultDownLoadVector of
  4732.             1 : Binary2Click( Self );
  4733.             2 : ToFile1Click( Self );
  4734.             3 : Change1Click( Self );
  4735.           end;
  4736.         end;
  4737.   end;
  4738. end;
  4739.  
  4740. procedure TCCINetCCForm.ListBox2DblClick(Sender: TObject);
  4741. var WorkingString ,
  4742.     NumberString    : String;
  4743.     TheIDNumber     : Integer;
  4744.     TheNGARecord    : PNewsGroupArticleRecord;
  4745. begin
  4746.   case Tag of
  4747.     2 : begin
  4748.           case DefaultDownLoadVector of
  4749.             1 : Binary1Click( Self );
  4750.             2 : ASCII1Click( Self );
  4751.             3 : ChangeLocal1Click( Self );
  4752.           end;
  4753.         end;
  4754.     5 : begin
  4755.           if ListBox2.Tag <> 5 then exit;
  4756.           if ListBox2.ItemIndex = -1 then exit;
  4757.           WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4758.           NumberString := TheFTPComponent.StripBrackets( WorkingString );
  4759.           TheIDNumber := StrToInt( NumberString );
  4760.           TheNGARecord := PNewsGroupArticleRecord(
  4761.            TheNGArticlesList.Items[ TheIDNumber ] );
  4762.           if TheNGARecord^.NGADownloaded then
  4763.           begin
  4764.             Memo1.Clear;
  4765.             try
  4766.               Memo1.Lines.LoadFromFile( NewsPath + '\' + TheNGARecord^.NGAArtFileName );
  4767.             except
  4768.               MessageDlg( 'Article Too Large to Load! Use Write to View [' +
  4769.                TheNGARecord^.NGAArtFilename + '.',
  4770.                mtError,[mbOK],0);
  4771.               exit;
  4772.             end;
  4773.             Label1.Caption := 'Subject:';
  4774.             ComboBox1.Text := TheNGARecord^.NGASubject;
  4775.             TheNGARecord^.NGARead := true;
  4776.             WorkingString := ListBox2.Items[ ListBox2.ItemIndex ];
  4777.             WorkingString[ 3 ] := 'R';
  4778.             ListBox2.Items[ ListBox2.ItemIndex ] := WorkingString;
  4779.           end
  4780.           else
  4781.           begin
  4782.             MessageDlg( 'Article Not Downloaded!',mtError,[mbOK],0);
  4783.           end;
  4784.         end;
  4785.     6 : begin
  4786.           if ListBox2.ItemIndex = -1 then exit;
  4787.           WorkingString := PEMailMessageRecord(
  4788.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRFileName;
  4789.           PEMailMessageRecord(
  4790.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRRead := true;;
  4791.           WorkingString := MailPath + '\' + WorkingString;
  4792.           Memo1.Clear;
  4793.           try
  4794.             Memo1.Lines.LoadFromFile( WorkingString );
  4795.           except
  4796.             MessageDlg( 'Article Too Large to Load! Use Write to View.',
  4797.              mtError,[mbOK],0);
  4798.             exit;
  4799.           end;
  4800.           Label1.Caption := 'Subject:';
  4801.           ComboBox1.Text := PEMailMessageRecord(
  4802.            TheMBMessagesList.Items[ ListBox2.ItemIndex ] )^.MRMessageSubject;
  4803.           PopulateLB2WithMessageHeaders;
  4804.         end;
  4805.   end;
  4806. end;
  4807.  
  4808. procedure TCCINetCCForm.ASCII1Click(Sender: TObject);
  4809. var Counter_1 : Integer;
  4810.     TheDir    : String;
  4811. begin
  4812.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4813.   begin
  4814.     if Listbox2.Selected[ Counter_1 ] then
  4815.     begin
  4816.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4817.       TheFTPComponent.
  4818.        SendASCIILocalFile( Listbox2.Items[ Counter_1 ] );
  4819.     end;
  4820.   end;
  4821.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4822.   { Put up remote directory via PWD and strip quotes }
  4823.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4824.   { Get the listings of directories and exit OK }
  4825.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4826. end;
  4827.  
  4828. procedure TCCINetCCForm.DeleteRemoteFiles1Click(Sender: TObject);
  4829. var Counter_1 : Integer;
  4830.     TheDir    : String;
  4831.     DoAll     : Boolean;
  4832.     TheResult : Integer;
  4833. begin
  4834.   DoAll := false;
  4835.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4836.   begin
  4837.     if Listbox1.Selected[ Counter_1 ] then
  4838.     begin
  4839.       if not DoAll then
  4840.       begin
  4841.         TheResult := MessageDlg( 'Delete Remote File ' +
  4842.          ListBox1.Items[ Counter_1 ] + ' ?',mtConfirmation,
  4843.           [mbYes,mbNo,mbCancel,mbAll],0 );
  4844.         case TheResult of
  4845.           mrYes : ;
  4846.           mrNo  : ;
  4847.           mrCancel : break;
  4848.           mrAll : begin
  4849.                     TheResult := mrYes;
  4850.                     DoAll := true;
  4851.                   end;
  4852.         end;
  4853.       end
  4854.       else TheResult := mrYes;
  4855.       if TheResult = mrYes then TheFTPComponent.
  4856.          DeleteRemoteFile( Listbox1.Items[ Counter_1 ] );
  4857.     end;
  4858.   end;
  4859.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4860.   { Put up remote directory via PWD and strip quotes }
  4861.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4862.   { Get the listings of directories and exit OK }
  4863.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4864. end;
  4865.  
  4866. procedure TCCINetCCForm.Binary1Click(Sender: TObject);
  4867. var Counter_1 : Integer;
  4868.     TheDir    : String;
  4869. begin
  4870.   for Counter_1 := 0 to Listbox2.Items.Count - 1 do
  4871.   begin
  4872.     if Listbox2.Selected[ Counter_1 ] then
  4873.     begin
  4874.       FileNameToXFer := ListBox2.Items[ Counter_1 ];
  4875.       TheFTPComponent.
  4876.        SendBinaryLocalFile( Listbox2.Items[ Counter_1 ] );
  4877.     end;
  4878.   end;
  4879.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4880.   { Put up remote directory via PWD and strip quotes }
  4881.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4882.   { Get the listings of directories and exit OK }
  4883.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4884. end;
  4885.  
  4886. procedure TCCINetCCForm.Delete3Click(Sender: TObject);
  4887. var Counter_1 : Integer;
  4888.     TheDir    : String;
  4889. begin
  4890.   for Counter_1 := 0 to Listbox1.Items.Count - 1 do
  4891.   begin
  4892.     if Listbox1.Selected[ Counter_1 ] then
  4893.     begin
  4894.       if ListBox1.Items[ Counter_1 ] <> '..' then
  4895.        TheFTPComponent.
  4896.         DeleteRemoteDirectory( Listbox1.Items[ Counter_1 ] );
  4897.     end;
  4898.   end;
  4899.   TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4900.   { Put up remote directory via PWD and strip quotes }
  4901.   Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4902.   { Get the listings of directories and exit OK }
  4903.   TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4904. end;
  4905.  
  4906. procedure TCCINetCCForm.Create1Click(Sender: TObject);
  4907. var TheDir : String;
  4908. begin
  4909.   OpenDialog1.Filename := '*.*';
  4910.   OpenDialog1.Title := 'Enter Remote Directory Name';
  4911.   if OpenDialog1.Execute then
  4912.   begin
  4913.     TheFTPComponent.
  4914.      CreateRemoteDirectory( ExtractFileName( OpenDialog1.FileName ));
  4915.     TheFTPComponent.GetRemoteWorkingDirectory( TheDir );
  4916.     { Put up remote directory via PWD and strip quotes }
  4917.     Label4.Caption := TheFTPComponent.GetQuotedString( TheDir );
  4918.     { Get the listings of directories and exit OK }
  4919.     TheFTPComponent.GetRemoteDirectoryListing( Listbox1 );
  4920.   end;
  4921. end;
  4922.  
  4923. procedure TCCINetCCForm.ListBox1Click(Sender: TObject);
  4924. var TheNGRecord : PNewsGroupRecord;
  4925.     TheMBRecord : PEMailMailboxRecord;
  4926. begin
  4927.   case ListBox1.Tag of
  4928.     5 : begin
  4929.           if ListBox1.ItemIndex = -1 then exit;
  4930.           TheNGRecord :=
  4931.            PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  4932.           TheNGArticlesList := TList( TheNGRecord^.GLTag );
  4933.           PopulateLB2WithArticleHeaders;
  4934.           ComboBox1.ItemIndex := ListBox1.ItemIndex;
  4935.         end;
  4936.     6 : begin
  4937.           if ListBox1.ItemIndex = -1 then exit;
  4938.           TheMBRecord :=
  4939.            PEMailMailboxRecord( TheEMailMailboxList.Items[ ListBox1.ItemIndex ] );
  4940.           TheMBMessagesList := TList( TheMBRecord^.MBLTag );
  4941.           PopulateLB2WithMessageHeaders;
  4942.         end;
  4943.   end;
  4944. end;
  4945.  
  4946. procedure TCCINetCCForm.UsenetNws1Click(Sender: TObject);
  4947. begin
  4948.   if TheFTPComponent.Connection_Established then
  4949.   begin
  4950.     MessageDlg( 'Must disconnect from current FTP session first!',
  4951.      mtError,[mbOK],0);
  4952.     exit;
  4953.   end;
  4954.   { Show The NNTP servers display }
  4955.   ListBox1.Clear;
  4956.   ListBox2.Clear;
  4957.   SetupNNTPSiteLists;
  4958.   NewsGroupListLoaded := false;
  4959.   SetupNNTPServersInfoDisplay;
  4960. end;
  4961.  
  4962. procedure TCCINetCCForm.Disconnect2Click(Sender: TObject);
  4963. begin
  4964.   SaveNNTPNewsGroupLists;
  4965.   DoNNTPDisconnect;
  4966.   DisableNNTPMenus;
  4967.   ListBox1.Clear;
  4968.   ListBox2.Clear;
  4969. end;
  4970.  
  4971. procedure TCCINetCCForm.News2Click(Sender: TObject);
  4972. begin
  4973.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 2;
  4974.   CCICPrefsDlg.Tag := 4;
  4975.   CCICPrefsDlg.ShowModal;
  4976. end;
  4977.  
  4978. procedure TCCINetCCForm.ConnectandUpdate1Click(Sender: TObject);
  4979. begin
  4980.   DoNNTPConnection( PConnectionsRecord(
  4981.      TheNewsServerList.Items[ ComboBox1.ItemIndex ] ));
  4982.   if TheNNTPComponent.Connection_Established then
  4983.   begin
  4984.     SetupNNTPNewsGroupLists;
  4985.     if NewsInitialUpdateVector = 1 then
  4986.     begin { Update all active newsgroups }
  4987.       TheNNTPComponent.CheckAllNewNews;
  4988.     end;
  4989.     { Bring up the files with current NG information }
  4990.     SetupNewsGroupListboxes;
  4991.   end;
  4992. end;
  4993.  
  4994. procedure TCCINetCCForm.CheckNewNews1Click(Sender: TObject);
  4995. begin
  4996.   TheNNTPComponent.CheckAllNewNews;
  4997.   SetupNewsGroupListboxes;
  4998. end;
  4999.  
  5000. procedure TCCINetCCForm.NewsServers1Click(Sender: TObject);
  5001. begin
  5002.   { Reset display to NNTP Servers }
  5003.   SetupNNTPServersInfoDisplay;
  5004.   { Show Modally to get the information }
  5005.   CCICInfoDlg.ShowModal;
  5006. end;
  5007.  
  5008. procedure TCCINetCCForm.SubscribedNewsgroups1Click(Sender: TObject);
  5009. begin
  5010.   { Reset display to Usenet Newsgroups }
  5011.   SetupNNTPNewsGroupsInfoDisplay;
  5012.   { Show Modally to get the information }
  5013.   CCICInfoDlg.ShowModal;
  5014.   TheNNTPComponent.CheckAllNewNews;
  5015.   SetupNewsGroupListboxes;
  5016. end;
  5017.  
  5018. procedure TCCINetCCForm.RetrieveMarked1Click(Sender: TObject);
  5019. var Counter_1   : Integer;
  5020.     TheNGRecord : PNewsGroupRecord;
  5021. begin
  5022.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5023.   begin
  5024.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5025.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  5026.     begin
  5027.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  5028.     end;
  5029.   end;
  5030.   SetupNewsGroupListboxes;
  5031. end;
  5032.  
  5033. procedure TCCINetCCForm.RetrieveAll1Click(Sender: TObject);
  5034. var Counter_1   : Integer;
  5035.     TheNGRecord : PNewsGroupRecord;
  5036. begin
  5037.   for Counter_1 := 0 to TheNewsRCList.Count - 1 do
  5038.   begin
  5039.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5040.     if TheNGRecord^.GSubscribed then
  5041.     begin
  5042.       TheNNTPComponent.GetAllArticleHeaders( TheNGRecord );
  5043.     end;
  5044.   end;
  5045.   SetupNewsGroupListboxes;
  5046. end;
  5047.  
  5048. procedure TCCINetCCForm.GetMarked1Click(Sender: TObject);
  5049. var TheNGRecord : PNewsGroupRecord;
  5050. begin
  5051.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5052.   TheNNTPComponent.DownloadAllMarkedArticleListings( TheNGRecord , ListBox2 );
  5053.   SetupNewsGroupListboxes;
  5054. end;
  5055.  
  5056. procedure TCCINetCCForm.NewArticle1Click(Sender: TObject);
  5057. begin
  5058.   if ListBox1.ItemIndex = -1 then exit;
  5059.   Memo1.Clear;
  5060.   TheNNTPComponent.SetNewsHeaders( Memo1 , ListBox1.ItemIndex );
  5061. end;
  5062.  
  5063. procedure TCCINetCCForm.FollowupArticle1Click(Sender: TObject);
  5064. begin
  5065.   if ListBox1.ItemIndex = -1 then exit;
  5066.   if ListBox2.ItemIndex = -1 then exit;
  5067.   Memo1.Clear;
  5068.   TheNNTPComponent.SetFUNewsHeaders( Memo1              ,
  5069.                                      ListBox1.ItemIndex ,
  5070.                                      ListBox2.ItemIndex   );
  5071. end;
  5072.  
  5073. procedure TCCINetCCForm.PutinQueue1Click(Sender: TObject);
  5074. var TheNGRecord : PNewsGroupRecord;
  5075.     TheNGARecord : PNewsGroupArticleRecord;
  5076.     WorkingList : TList;
  5077.     WorkingFilename : String;
  5078.     Holdingposition : Integer;
  5079. begin
  5080.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5081.   WorkingList := TList( TheNGRecord^.GLTag );
  5082.   New( TheNGARecord );
  5083.   with TheNGARecord^ do
  5084.   begin
  5085.     NGAGroupname   := TheNGRecord^.GRealName;
  5086.     NGASubject     := TheNNTPComponent.GetHeaderSubject( TStringList( Memo1.Lines ));
  5087.     NGANumber      := TheNGRecord^.GHighestAvailable + WorkingList.Count;
  5088.     NGADownloaded  := true;
  5089.     NGASender      := 'CIUPKC158';
  5090.     NGARead        := false;
  5091.     NGAPosted      := false;
  5092.     WorkingFileName := 'AR' + IntToStr( NGANumber );
  5093.     if Length( WorkingFileName ) > 8 then
  5094.      WorkingFileName := Copy( WorkingFileName ,1 , 8 );
  5095.     WorkingFileName := WorkingFileName + '.' + IntToStr( TheNGRecord^.GIDNumber );
  5096.     NGAArtFileName := WorkingFileName;
  5097.   end;
  5098.   WorkingList.Add( TheNGARecord );
  5099.   Memo1.Lines.SaveToFile( NewsPath + '\' + WorkingFileName );
  5100.   HoldingPosition := ListBox1.itemindex;
  5101.   SetupNewsGroupListboxes;
  5102.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HoldingPosition ] );
  5103.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5104.   PopulateLB2WithArticleHeaders;
  5105. end;
  5106.  
  5107. procedure TCCINetCCForm.CurrentArticle1Click(Sender: TObject);
  5108. var TheNGARecord : PNewsGroupArticleRecord;
  5109.     TheNGRecord  : PNewsGroupRecord;
  5110.     HP : Integer;
  5111. begin
  5112.   HP := ListBox1.itemindex;
  5113.   PutInQueue1Click( Self );
  5114.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ HP ] );
  5115.   TheNGArticlesList := TList( TheNGRecord^.GLTag );
  5116.   TheNGARecord := PNewsGroupArticleRecord( TheNGArticlesList.Items[ TheNGArticlesList.Count - 1 ] );
  5117.   TheNNTPComponent.UploadArticleListing( TheNGARecord );
  5118. end;
  5119.  
  5120. procedure TCCINetCCForm.EntireQueue1Click(Sender: TObject);
  5121. var TheNGRecord : PNewsGroupRecord;
  5122. begin
  5123.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5124.   TheNNTPComponent.UploadAllArticleListings( TheNGRecord );
  5125. end;
  5126.  
  5127. procedure TCCINetCCForm.AllReadArticles1Click(Sender: TObject);
  5128. var TheNGRecord : PNewsGroupRecord;
  5129. begin
  5130.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5131.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5132.   SetupNewsGroupListboxes;
  5133. end;
  5134.  
  5135. procedure TCCINetCCForm.AllMarkedArticles1Click(Sender: TObject);
  5136. var TheNGRecord : PNewsGroupRecord;
  5137.     TheNGARecord : PNewsGroupArticleRecord;
  5138.     WorkingList : TList;
  5139.     Counter_1 : Integer;
  5140. begin
  5141.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5142.   WorkingList := TList( TheNGRecord^.GLTag );
  5143.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5144.   begin
  5145.     if ListBox2.Selected[ Counter_1 ] then
  5146.     begin
  5147.       TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5148.       TheNGARecord^.NGARead := true;
  5149.     end;
  5150.   end;
  5151.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5152.   SetupNewsGroupListboxes;
  5153. end;
  5154.  
  5155. procedure TCCINetCCForm.AllAvailableArticles1Click(Sender: TObject);
  5156. var TheNGRecord : PNewsGroupRecord;
  5157.     TheNGARecord : PNewsGroupArticleRecord;
  5158.     WorkingList : TList;
  5159.     Counter_1  : Integer;
  5160. begin
  5161.   TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5162.   WorkingList := TList( TheNGRecord^.GLTag );
  5163.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5164.   begin
  5165.     TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_1 ] );
  5166.     TheNGARecord^.NGARead := true;
  5167.   end;
  5168.   TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5169.   SetupNewsGroupListboxes;
  5170. end;
  5171.  
  5172. procedure TCCINetCCForm.DownloadActiveNewsgroups1Click(Sender: TObject);
  5173. begin
  5174.   if MessageDlg( 'This will take considerable time. Proceed?',mtConfirmation,
  5175.    mbYesNoCancel,0) = mrYes then
  5176.   begin
  5177.     Memo1.Clear;
  5178.     TheNNTPComponent.GetListofAvailableNewsGroups;
  5179.   end;
  5180. end;
  5181.  
  5182. procedure TCCINetCCForm.UUEncode1Click(Sender: TObject);
  5183. begin
  5184.   OpenDialog1.Filename := '*.*';
  5185.   OpenDialog1.Title := 'Select File to UUENCODE';
  5186.   if OpenDialog1.Execute then
  5187.   begin
  5188.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5189.     TheUUObject.EncodeCurrentInputs;
  5190.   end;
  5191. end;
  5192.  
  5193. procedure TCCINetCCForm.Load1Click(Sender: TObject);
  5194. var Memo2 : TMemo;
  5195.     Counter_1 : Integer;
  5196. begin
  5197.   OpenDialog1.Filename := '*.txt';
  5198.   OpenDialog1.Title := 'Select File to load into Memo';
  5199.   if OpenDialog1.Execute then
  5200.   begin
  5201.     Memo2 := TMemo.Create( Self );
  5202.     Memo2.Parent := Self;
  5203.     Memo2.Visible := false;
  5204.     Memo2.Width := Memo1.Width;
  5205.     Memo2.Height := Memo1.Height;
  5206.     Memo2.Lines.LoadFromFile( OpenDialog1.FileName );
  5207.     for Counter_1 := 0 to Memo2.Lines.Count - 1 do
  5208.      Memo1.Lines.Add( Memo2.Lines[ Counter_1 ] );
  5209.     Memo2.Free;
  5210.   end;
  5211. end;
  5212.  
  5213. procedure TCCINetCCForm.Save1Click(Sender: TObject);
  5214. begin
  5215.   SaveDialog1.Filename := '*.txt';
  5216.   SaveDialog1.Title := 'Select File to Save Memo to';
  5217.   if OpenDialog1.Execute then
  5218.   begin
  5219.     Memo1.Lines.SaveToFile( SaveDialog1.FileName );
  5220.   end;
  5221. end;
  5222.  
  5223. procedure TCCINetCCForm.EMail1Click(Sender: TObject);
  5224. begin
  5225.   if TheFTPComponent.Connection_Established then
  5226.   begin
  5227.     MessageDlg( 'Must disconnect from current FTP session first!',
  5228.      mtError,[mbOK],0);
  5229.     exit;
  5230.   end;
  5231.   if TheNNTPComponent.Connection_Established then
  5232.   begin
  5233.     MessageDlg( 'Must disconnect from current NNTP session first!',
  5234.      mtError,[mbOK],0);
  5235.     exit;
  5236.   end;
  5237.   { Show The POP3SMTP servers display }
  5238.   ListBox1.Clear;
  5239.   ListBox2.Clear;
  5240.   SetupEMailServerStatus;
  5241.   EnablePOP3SMTPMenus;
  5242.   SetupEMailServersInfoDisplay;
  5243. end;
  5244.  
  5245. procedure TCCINetCCForm.CheckMail1Click(Sender: TObject);
  5246. begin
  5247.   WhichServer := ComboBox1.ItemIndex + 1;
  5248.   if not EMailLoaded then
  5249.   begin
  5250.     LoadEMailMailBoxFile( WhichServer );
  5251.     LoadEMailCorrespondentsFile;
  5252.     EmailLoaded := true;
  5253.   end;
  5254.   DoPOP3Connection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5255.   ThePOP3SMTPComponent.DownloadAllMessageListings(
  5256.    PEMailMailBoxRecord( TheEMailMailboxList.Items[ 0 ] ));
  5257.   ThePOP3SMTPComponent.POP3Disconnect;
  5258.   SetupEMailListBoxes;
  5259. end;
  5260.  
  5261. procedure TCCINetCCForm.CreateNewMessage1Click(Sender: TObject);
  5262. begin
  5263.   Label2.Visible := true;
  5264.   Label3.visible := true;
  5265.   ComboBox2.Visible := true;
  5266.   ComboBox3.visible := true;
  5267.   ThePOP3SMTPComponent.SetMailHeaders( Memo1 ,
  5268.    PConnectionsRecord( TheEMailServerList.Items[ WhichServer - 1 ] ));
  5269.   NewMessageInProgress := true;
  5270. end;
  5271.  
  5272. procedure TCCINetCCForm.ReplyToCurrentMessage1Click(Sender: TObject);
  5273. begin
  5274.   Label2.Visible := true;
  5275.   Label3.visible := true;
  5276.   ComboBox2.Visible := true;
  5277.   ComboBox3.visible := true;
  5278.   ThePOP3SMTPComponent.SetReplyMailHeaders( Memo1 ,
  5279.    PConnectionsRecord( TheEMailServerList.Items[ WhichServer - 1 ] ) ,
  5280.    PEMailMailboxRecord( TheEMailMailboxList.Items[ ListBox1.ItemIndex ] ) ,
  5281.    ListBox2.ItemIndex );
  5282.   NewMessageInProgress := true;
  5283. end;
  5284.  
  5285. procedure TCCINetCCForm.SendCurrentMessage1Click(Sender: TObject);
  5286. var TheEMMRecord : PEMailMessageRecord;
  5287.     WorkingNumber : Integer;
  5288.     WorkingFileName : String;
  5289.     WorkingList     : TList;
  5290. begin
  5291.   Label2.Visible := false;
  5292.   Label3.visible := false;
  5293.   ComboBox2.Visible := false;
  5294.   ComboBox3.visible := false;
  5295.   if not NewMessageInProgress then exit;
  5296.   NewMessageInProgress := false;
  5297.   New( TheEMMRecord );
  5298.   ThePOP3SMTPComponent.ExtractHeaderInfoFromMemo( Memo1 , TheEMMRecord );
  5299.   WorkingNumber := ListBox2.Items.Count + 1;
  5300.   with TheEMMRecord^ do
  5301.   begin
  5302.     MRSent := false;
  5303.     WorkingFileName := 'EM' + IntToStr( WorkingNumber );
  5304.     if Length( WorkingFileName ) > 8 then WorkingFileName :=
  5305.      Copy( WorkingFileName , 1 , 8 );
  5306.     WorkingFileName := WorkingFileName + '.2';
  5307.     MRFileName := WorkingFileName;
  5308.     WorkingFileName := MailPath + '\' + WorkingFileName;
  5309.     Memo1.Lines.SaveToFile( WorkingFileName );
  5310.   end;
  5311.    Inc( PEMailMailBoxRecord(
  5312.    TheEMailMailBoxList.Items[ 1 ] )^.MBTotal );
  5313.    Inc( PEMailMailBoxRecord(
  5314.    TheEMailMailBoxList.Items[ 1 ] )^.MBUnSentTotal );
  5315.    WorkingList := TList( PEMailMailBoxRecord(
  5316.    TheEMailMailBoxList.Items[ 1 ] )^.MBLTag );
  5317.   WorkingList.Add( TheEMMRecord );
  5318.   PEMailMailBoxRecord(
  5319.    TheEMailMailBoxList.Items[ 1 ] )^.MBLTag :=
  5320.     Longint( WorkingList );
  5321.   If EMQueueVector = 2 then
  5322.   begin
  5323.     DoSMTPConnection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5324.     ThePOP3SMTPComponent.UploadMessageListing( TheEMMRecord );
  5325.     {ThePOP3SMTPComponent.SMTPDisconnect;}
  5326.   end;
  5327.   TheMBMessagesList := WorkingList;
  5328.   SetupEMailListBoxes;
  5329.   Memo1.Clear;
  5330. end;
  5331.  
  5332. procedure TCCINetCCForm.SendQueue1Click(Sender: TObject);
  5333. var WorkingList     : TList;
  5334. begin
  5335.   SendCurrentMessage1Click( Self );
  5336.   Memo1.Clear;
  5337.   DoSMTPConnection( TheEMailServerList.Items[ WhichServer - 1 ] );
  5338.   ThePOP3SMTPComponent.UploadAllMessageListings( PConnectionsRecord(
  5339.    TheEMailServerList.Items[ WhichServer - 1 ] ),
  5340.    PEMailMailboxRecord( TheEMailMailboxList.Items[ 1 ] ));
  5341.   {ThePOP3SMTPComponent.SMTPDisconnect;}
  5342.    WorkingList := TList( PEMailMailBoxRecord(
  5343.    TheEMailMailBoxList.Items[ 1 ] )^.MBLTag );
  5344.   TheMBMessagesList := WorkingList;
  5345.   SetupEMailListBoxes;
  5346. end;
  5347.  
  5348. procedure TCCINetCCForm.MailServers1Click(Sender: TObject);
  5349. begin
  5350.   SetupEmailServersInfoDisplay;
  5351.   CCICInfoDlg.ShowModal;
  5352. end;
  5353.  
  5354. procedure TCCINetCCForm.Mailboxes1Click(Sender: TObject);
  5355. begin
  5356.   SetupEmailMailboxInfoDisplay;
  5357.   CCICInfoDlg.ShowModal;
  5358.   SetupEMailListBoxes;
  5359. end;
  5360.  
  5361. procedure TCCINetCCForm.Correspondents1Click(Sender: TObject);
  5362. begin
  5363.   SetupEmailCorrespondentsInfoDisplay;
  5364.   CCICInfoDlg.ShowModal;
  5365. end;
  5366.  
  5367. procedure TCCINetCCForm.EMail3Click(Sender: TObject);
  5368. begin
  5369.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 0;
  5370.   CCICPrefsDlg.Tag := 6;
  5371.   CCICPrefsDlg.ShowModal;
  5372. end;
  5373.  
  5374. procedure TCCINetCCForm.Paths1Click(Sender: TObject);
  5375. begin
  5376.   CCICPrefsDlg.TabbedNoteBook1.PageIndex := 3;
  5377.   CCICPrefsDlg.Tag := 3;
  5378.   CCICPrefsDlg.ShowModal;
  5379. end;
  5380.  
  5381. procedure TCCINetCCForm.ExitEMailRequired1Click(Sender: TObject);
  5382. begin
  5383.   if not ThePOP3SMTPComponent.Connection_Established then exit;
  5384.   DoPOP3SMTPDisconnect;
  5385.   SaveEMailMailBoxFile( WhichServer );
  5386.   SaveEMailCorrespondentsFile;
  5387.   DisablePOP3SMTPMenus;
  5388.   EMailLoaded := false;
  5389. end;
  5390.  
  5391. procedure TCCINetCCForm.TrashMarkedMessages1Click(Sender: TObject);
  5392. begin
  5393.   ThePOP3SMTPComponent.TrashAllMarkedMessages( ListBox2 ,
  5394.    PEMailMailboxRecord( TheEMailMailBoxList.Items[ ListBox1.Itemindex ] ));
  5395.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5396.    TheEMailMailBoxList.Items[ ListBox1.Itemindex ] )^.MBLTag );
  5397.   PopulateLB2WithMessageHeaders;
  5398. end;
  5399.  
  5400. procedure TCCINetCCForm.EmptyTrash1Click(Sender: TObject);
  5401. var Counter_1 : Integer;
  5402. begin
  5403.   for Counter_1 := 0 to TheEMailMailboxList.Count - 1 do
  5404.   begin
  5405.     ThePOP3SMTPComponent.PurgeTrashedMessageListings(
  5406.      PEMailMailBoxRecord( TheEMailMailboxList.Items[ Counter_1 ] ));
  5407.   end;
  5408.   TheMBMessagesList := TList( PEMailMailboxRecord(
  5409.    TheEMailMailBoxList.Items[ 0 ] )^.MBLTag );
  5410.   SetupEmailListboxes;
  5411. end;
  5412.  
  5413. procedure TCCINetCCForm.ComboBox2Change(Sender: TObject);
  5414. var WhichCorrespondent : Integer;
  5415.     TheName            : String;
  5416. begin
  5417.   case Tag of
  5418.     6 : begin
  5419.           if not NewMessageInProgress then exit;
  5420.           WhichCorrespondent := ComboBox2.ItemIndex;
  5421.           if WhichCorrespondent = -1 then exit;
  5422.           TheName := PConnectionsRecord(
  5423.            TheCorrespondentsList.Items[ WhichCorrespondent ] )^.CIPAddress;
  5424.           ThePOP3SMTPComponent.SetRecipient( Memo1 , TheName );
  5425.         end;
  5426.   end;
  5427. end;
  5428.  
  5429. procedure TCCINetCCForm.ComboBox3Change(Sender: TObject);
  5430. var WhichCorrespondent : Integer;
  5431.     TheName            : String;
  5432. begin
  5433.   case Tag of
  5434.     6 : begin
  5435.           if not NewMessageInProgress then exit;
  5436.           WhichCorrespondent := ComboBox3.ItemIndex;
  5437.           if WhichCorrespondent = -1 then exit;
  5438.           TheName := PConnectionsRecord(
  5439.            TheCorrespondentsList.Items[ WhichCorrespondent ] )^.CIPAddress;
  5440.           ThePOP3SMTPComponent.SetCarbonCopy( Memo1 , TheName );
  5441.         end;
  5442.   end;
  5443. end;
  5444.  
  5445. procedure TCCINetCCForm.MIMEDecode1Click(Sender: TObject);
  5446. var Counter_1    : Integer;
  5447.     TheEMMRecord : PEmailMessageRecord;
  5448. begin
  5449.   for Counter_1 := 0 to ListBox2.Items.Count - 1 do
  5450.   begin
  5451.     if ListBox2.Selected[ Counter_1 ] then
  5452.     begin
  5453.       TheEMMRecord :=
  5454.        PEMailMessageRecord( TheMBMessagesList.Items[ Counter_1 ] );
  5455.       TheMIMEObject.TheInputFileName := MailPath + '\' +
  5456.        TheEMMRecord^.MRFileName;
  5457.       TheMIMEObject.DecodeMIMEFile;
  5458.     end;
  5459.   end;
  5460. end;
  5461.  
  5462. procedure TCCINetCCForm.Cut1Click(Sender: TObject);
  5463. begin
  5464.   Memo1.CutToClipboard;
  5465. end;
  5466.  
  5467. procedure TCCINetCCForm.Copy1Click(Sender: TObject);
  5468. begin
  5469.   Memo1.CopyToClipboard;
  5470. end;
  5471.  
  5472. procedure TCCINetCCForm.CopytoFile1Click(Sender: TObject);
  5473. var TempMemo : TMemo;
  5474. begin
  5475.   TempMemo := TMemo.Create( self );
  5476.   TempMemo.parent := self;
  5477.   Tempmemo.Visible := false;
  5478.   TempMemo.Width := Memo1.Width;
  5479.   TempMemo.Height := Memo1.Height;
  5480.   Memo1.CopyToClipboard;
  5481.   TempMemo.PasteFromClipboard;
  5482.   SaveDialog1.Filename := '*.TXT';
  5483.   SaveDialog1.Title := 'Select File to Save To';
  5484.   if SaveDialog1.Execute then TempMemo.Lines.SaveToFile( SaveDialog1.Filename );
  5485.   TempMemo.Free;
  5486. end;
  5487.  
  5488. procedure TCCINetCCForm.Paste1Click(Sender: TObject);
  5489. begin
  5490.   Memo1.PasteFromClipboard;
  5491. end;
  5492.  
  5493. procedure TCCINetCCForm.PastefromFile1Click(Sender: TObject);
  5494. var TempMemo : TMemo;
  5495. begin
  5496.   TempMemo := TMemo.Create( self );
  5497.   TempMemo.parent := self;
  5498.   Tempmemo.Visible := false;
  5499.   TempMemo.Width := Memo1.Width;
  5500.   TempMemo.Height := Memo1.Height;
  5501.   OpenDialog1.Filename := '*.*';
  5502.   OpenDialog1.Title := 'Select File to Paste From';
  5503.   if OpenDialog1.Execute then TempMemo.Lines.LoadFromFile( OpenDialog1.Filename );
  5504.   TempMemo.SelectAll;
  5505.   TempMemo.CopyToClipboard;
  5506.   Memo1.PasteFromClipboard;
  5507.   TempMemo.Free;
  5508. end;
  5509.  
  5510. procedure TCCINetCCForm.SpeedButton5Click(Sender: TObject);
  5511. begin
  5512.   case Tag of
  5513.     5 : AllMarkedArticles1Click( Self );
  5514.     6 : TrashMarkedMessages1Click( self ); 
  5515.   end;
  5516. end;
  5517.  
  5518. procedure TCCINetCCForm.SpeedButton3Click(Sender: TObject);
  5519. begin
  5520.   case Tag of
  5521.     6 : MIMEDecode1Click( self );
  5522.   end;
  5523. end;
  5524.  
  5525. procedure TCCINetCCForm.SpeedButton1Click(Sender: TObject);
  5526. begin
  5527.   case Tag of
  5528.     5 : begin
  5529.           if ListBox2.Items.Count = 0 then exit;
  5530.           Listbox2.multiselect := false;
  5531.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5532.           ListBox2.ItemIndex := Listbox2.ItemIndex - 1;
  5533.           if ListBox2.Itemindex < 0 then
  5534.            Listbox2.Itemindex := ListBox2.Items.Count - 1;
  5535.           ListBox2DblClick( Self );
  5536.           ListBox2.Multiselect := true;
  5537.           ListBox2.SetFocus;
  5538.         end;
  5539.     6 : begin
  5540.           if ListBox2.Items.Count = 0 then exit;
  5541.           Listbox2.multiselect := false;
  5542.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5543.           ListBox2.ItemIndex := Listbox2.ItemIndex - 1;
  5544.           if ListBox2.Itemindex < 0 then
  5545.            Listbox2.Itemindex := ListBox2.Items.Count - 1;
  5546.           ListBox2DblClick( Self );
  5547.           ListBox2.Multiselect := true;
  5548.           ListBox2.SetFocus;
  5549.         end;
  5550.   end;
  5551. end;
  5552.  
  5553. procedure TCCINetCCForm.SpeedButton2Click(Sender: TObject);
  5554. begin
  5555.   case Tag of
  5556.     5 : begin
  5557.           if ListBox2.Items.Count = 0 then exit;
  5558.           ListBox2.MultiSelect := false;
  5559.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5560.           ListBox2.ItemIndex := Listbox2.ItemIndex + 1;
  5561.           if ListBox2.Itemindex > ListBox2.Items.Count - 1 then
  5562.            Listbox2.Itemindex := 0;
  5563.           ListBox2DblClick( Self );
  5564.           ListBox2.MultiSelect := true;
  5565.           ListBox2.SetFocus;
  5566.         end;
  5567.     6 : begin
  5568.           if ListBox2.Items.Count = 0 then exit;
  5569.           ListBox2.MultiSelect := false;
  5570.           If ListBox2.ItemIndex = -1 then ListBox2.ItemIndex := 0;
  5571.           ListBox2.ItemIndex := Listbox2.ItemIndex + 1;
  5572.           if ListBox2.Itemindex > ListBox2.Items.Count - 1 then
  5573.            Listbox2.Itemindex := 0;
  5574.           ListBox2DblClick( Self );
  5575.           ListBox2.MultiSelect := true;
  5576.           ListBox2.SetFocus;
  5577.         end;
  5578.   end;
  5579. end;
  5580.  
  5581. procedure TCCINetCCForm.ListBox2Click(Sender: TObject);
  5582. var TheWorkingList : TList;
  5583.     TheNGARecord : PNewsGroupArticleRecord;
  5584.     TheNGRecord : PNewsGroupRecord;
  5585.     TheWorkingName : String;
  5586. begin
  5587.   if ListBox2.Tag = 9 then
  5588.   begin
  5589.     TheNGRecord :=
  5590.      PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5591.     TheWorkingList := TList( TheNGRecord^.GLTag );
  5592.     TheNGARecord := PNewsGroupArticleRecord(
  5593.      TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5594.     TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5595.     TheUUDecodeList.Add( TheWorkingName );
  5596.     exit;
  5597.   end;
  5598.   case Tag of
  5599.     5 : begin
  5600.           If ListBox2.Items.Count = 0 then exit;
  5601.           ComboBox1.Text := ListBox2.Items[ ListBox2.ItemIndex ];
  5602.         end;
  5603.   end;
  5604. end;
  5605.  
  5606. procedure TCCINetCCForm.AbortNewsgroupDownload1Click(Sender: TObject);
  5607. begin
  5608.   GlobalAbortedFlag := true;
  5609. end;
  5610.  
  5611. procedure TCCINetCCForm.Marked1Click(Sender: TObject);
  5612. var Counter_1,
  5613.     Counter_2   : Integer;
  5614.     TheNGRecord : PNewsGroupRecord;
  5615.     TheNGARecord : PNewsGroupArticleRecord;
  5616.     WorkingList : TList;
  5617. begin
  5618.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5619.   begin
  5620.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5621.     if (( TheNGRecord^.GSubscribed ) and ( ListBox1.Selected[ Counter_1 ] )) then
  5622.     begin
  5623.       WorkingList := TList( TheNGRecord^.GLTag );
  5624.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5625.       begin
  5626.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5627.         TheNGARecord^.NGARead := true;
  5628.       end;
  5629.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5630.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5631.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5632.       TheNGRecord^.GTotalNew := 0;
  5633.       TheNGRecord^.GTotalArticles := 0;
  5634.     end;
  5635.   end;
  5636.   SetupNewsGroupListboxes;
  5637. end;
  5638.  
  5639. procedure TCCINetCCForm.All1Click(Sender: TObject);
  5640. var Counter_1,
  5641.     Counter_2   : Integer;
  5642.     TheNGRecord : PNewsGroupRecord;
  5643.     TheNGARecord : PNewsGroupArticleRecord;
  5644.     WorkingList : TList;
  5645. begin
  5646.   for Counter_1 := 0 to ListBox1.Items.Count - 1 do
  5647.   begin
  5648.     TheNGRecord := PNewsGroupRecord( TheNewsRCList.Items[ Counter_1 ] );
  5649.     if TheNGRecord^.GSubscribed then
  5650.     begin
  5651.       WorkingList := TList( TheNGRecord^.GLTag );
  5652.       for Counter_2 := 0 to ListBox2.Items.Count - 1 do
  5653.       begin
  5654.         TheNGARecord := PNewsGroupArticleRecord( WorkingList.Items[ Counter_2 ] );
  5655.         TheNGARecord^.NGARead := true;
  5656.       end;
  5657.       TheNGRecord^.GLowest := TheNGRecord^.GHighestAvailable;
  5658.       TheNGRecord^.GHighest := TheNGRecord.GLowest;
  5659.       TheNGRecord^.GTotalNew := 0;
  5660.       TheNGRecord^.GTotalArticles := 0;
  5661.       TheNNTPComponent.PurgeReadSentArticleListings( TheNGRecord );
  5662.     end;
  5663.   end;
  5664.   SetupNewsGroupListboxes;
  5665. end;
  5666.  
  5667. procedure TCCINetCCForm.File1Click(Sender: TObject);
  5668. begin
  5669.   OpenDialog1.Filename := '*.uue';
  5670.   OpenDialog1.Filter := 'UUEncode Files|*.uue|All Files *.*';
  5671.   OpenDialog1.Title := 'Select File To Decode';
  5672.   if OpenDialog1.Execute then
  5673.   begin
  5674.     TheUUObject.SetInputFileName( OpenDialog1.FileName );
  5675.     TheUUObject.SetMultifileVector( CMV_SINGLE );
  5676.     TheUUObject.Decode;
  5677.   end;
  5678. end;
  5679.  
  5680. procedure TCCINetCCForm.SelectedArticle1Click(Sender: TObject);
  5681. var TheWorkingList : TList;
  5682.     TheNGARecord : PNewsGroupArticleRecord;
  5683.     TheNGRecord : PNewsGroupRecord;
  5684.     TheWorkingName : String;
  5685. begin
  5686.   TheNGRecord :=
  5687.    PNewsGroupRecord( TheNewsRCList.Items[ ListBox1.ItemIndex ] );
  5688.   TheWorkingList := TList( TheNGRecord^.GLTag );
  5689.   TheNGARecord := PNewsGroupArticleRecord(
  5690.    TheWorkingList.Items[ ListBox2.ItemIndex ] );
  5691.   TheWorkingName := NewsPath + '\' + TheNGARecord^.NGAArtFileName;
  5692.   TheUUObject.SetInputFileName( TheWorkingName );
  5693.   TheUUObject.SetMultifileVector( CMV_SINGLE );
  5694.   TheUUObject.Decode;
  5695. end;
  5696.  
  5697. procedure TCCINetCCForm.SelectMultipleArticles1Click(Sender: TObject);
  5698. begin
  5699.   { Set tag so that listbox knows to keep track of hits}
  5700.   ListBox2.Tag := 9;
  5701.   ListBox2.MultiSelect := false;
  5702.   TheUUDecodeList := TStringList.Create;
  5703. end;
  5704.  
  5705. procedure TCCINetCCForm.DecodeSelections1Click(Sender: TObject);
  5706. begin
  5707.   ListBox2.Tag := 5;
  5708.   ListBox2.MultiSelect := True;
  5709.   if TheUUDecodeList.Count = 0 then exit;
  5710.   TheUUObject.SetMultipleFilesList( TheUUDecodeList );
  5711.   TheUUObject.SetMultifileVector( CMV_MULTI );
  5712.   TheUUObject.Decode;
  5713.   TheUUDecodeList.Free;
  5714. end;
  5715.  
  5716. procedure TCCINetCCForm.SpeedButton4Click(Sender: TObject);
  5717. begin
  5718.   case Tag of
  5719.     5 : begin
  5720.           SelectedArticle1Click( Self );
  5721.         end;
  5722.   end;
  5723. end;
  5724.  
  5725. end.
  5726.  
  5727.